Cascade
Loading...
Searching...
No Matches
Buzzware.Cascade.FileSystemClassCache< Model, IdType > Class Template Reference

A simple file system-based cache for storing and retrieving instances of a model class with specified ID type. Implements IModelClassCache to fetch, store, and remove model instances and collections using JSON serialization. More...

Inheritance diagram for Buzzware.Cascade.FileSystemClassCache< Model, IdType >:
Buzzware.Cascade.IModelClassCache

Public Member Functions

 FileSystemClassCache (string fileDir, CascadeJsonSerialization? serialization=null)
 FileSystemClassCache Constructor Initializes directories for models and collections, and initializes the JSON serialization mechanism.
async Task< OpResponseFetch (RequestOp requestOp)
 Fetches a model or collection from the file system based on the specified request operation.
async Task Setup ()
 Implement this for any setup required.
async Task Store (object id, object model, long arrivedAt)
 Stores a model instance asynchronously to the file system based on its id.
async Task StoreAll (IReadOnlyList< object > results, long arrivedAt)
async Task StoreCollection (string key, IEnumerable ids, long arrivedAt)
 Stores a collection of model ids to the file system under a specific key.
async Task Remove (object id)
 Removes a model instance from the file system based on its identifier.
async Task ClearAll (bool exceptHeld, DateTime? olderThan=null)
 Clears all stored models and collections from the file system. Optionally exempts held or recently modified files.

Protected Member Functions

async Task SerializeToPathAsync (string aPath, object aObject, long timeMs)
 Serializes an object to a specified file path asynchronously and sets the file's last write time.
async Task< T?> DeserializeFromPathAsync< T > (string aPath)
 Deserializes and returns an object from the given file path.

Properties

CascadeDataLayerCascade [get, set]
 Reference to cascade data layer.

Detailed Description

A simple file system-based cache for storing and retrieving instances of a model class with specified ID type. Implements IModelClassCache to fetch, store, and remove model instances and collections using JSON serialization.

Type Constraints
Model :class 

Member Function Documentation

◆ ClearAll()

async Task Buzzware.Cascade.FileSystemClassCache< Model, IdType >.ClearAll ( bool exceptHeld,
DateTime? olderThan = null )
inline

Clears all stored models and collections from the file system. Optionally exempts held or recently modified files.

Parameters
exceptHeldIf true, retains files marked as held in cache.
olderThanOptional DateTime to retain files modified after a certain date.

Implements Buzzware.Cascade.IModelClassCache.

◆ DeserializeFromPathAsync< T >()

async Task< T?> Buzzware.Cascade.FileSystemClassCache< Model, IdType >.DeserializeFromPathAsync< T > ( string aPath)
inlineprotected

Deserializes and returns an object from the given file path.

Template Parameters
TThe type of the object to deserialize.
Parameters
aPathThe path of the file from which to deserialize the object.
Returns
The deserialized object of type T, or null if deserialization fails.

◆ Fetch()

async Task< OpResponse > Buzzware.Cascade.FileSystemClassCache< Model, IdType >.Fetch ( RequestOp requestOp)
inline

Fetches a model or collection from the file system based on the specified request operation.

Parameters
requestOpThe operation that specifies what to fetch.
Returns
Operation response containing the fetched object or a failed status if not found.

Implements Buzzware.Cascade.IModelClassCache.

◆ FileSystemClassCache()

Buzzware.Cascade.FileSystemClassCache< Model, IdType >.FileSystemClassCache ( string fileDir,
CascadeJsonSerialization? serialization = null )
inline

FileSystemClassCache Constructor Initializes directories for models and collections, and initializes the JSON serialization mechanism.

Parameters
fileDirThe base directory for storing model and collection files.
serializationOptional JSON serialization object; uses default if not specified.

◆ Remove()

async Task Buzzware.Cascade.FileSystemClassCache< Model, IdType >.Remove ( object id)
inline

Removes a model instance from the file system based on its identifier.

Parameters
idThe identifier of the model instance to remove.

Implements Buzzware.Cascade.IModelClassCache.

◆ SerializeToPathAsync()

async Task Buzzware.Cascade.FileSystemClassCache< Model, IdType >.SerializeToPathAsync ( string aPath,
object aObject,
long timeMs )
inlineprotected

Serializes an object to a specified file path asynchronously and sets the file's last write time.

Parameters
aPathThe target file path for serialized output.
aObjectThe object to serialize.
timeMsThe timestamp in milliseconds to set as the file's last write time.

◆ Setup()

async Task Buzzware.Cascade.FileSystemClassCache< Model, IdType >.Setup ( )
inline

Implement this for any setup required.

Returns

Implements Buzzware.Cascade.IModelClassCache.

◆ Store()

async Task Buzzware.Cascade.FileSystemClassCache< Model, IdType >.Store ( object id,
object model,
long arrivedAt )
inline

Stores a model instance asynchronously to the file system based on its id.

Parameters
idIdentifier of the model instance.
modelThe model object to store.
arrivedAtTimestamp of when the model arrived, used for file timestamping.

Implements Buzzware.Cascade.IModelClassCache.

◆ StoreAll()

async Task Buzzware.Cascade.FileSystemClassCache< Model, IdType >.StoreAll ( IReadOnlyList< object > results,
long arrivedAt )
inline

◆ StoreCollection()

async Task Buzzware.Cascade.FileSystemClassCache< Model, IdType >.StoreCollection ( string key,
IEnumerable ids,
long arrivedAt )
inline

Stores a collection of model ids to the file system under a specific key.

Parameters
keyThe key under which the collection is stored.
idsThe collection of identifiers to store.
arrivedAtTimestamp of when the collection was stored, used for file timestamping.

Implements Buzzware.Cascade.IModelClassCache.

Property Documentation

◆ Cascade

CascadeDataLayer? Buzzware.Cascade.FileSystemClassCache< Model, IdType >.Cascade
getset

Reference to cascade data layer.

Implements Buzzware.Cascade.IModelClassCache.


The documentation for this class was generated from the following file:
  • Buzzware.Cascade/FileSystemClassCache.cs