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

Provides a file based IModelClassCache which stores serialized model classes and their collections in directory-based file storage. It uses hashing and memory storage to speed up some reads and writes. More...

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

Public Member Functions

 FastFileClassCache (string fileDir, CascadeJsonSerialization? serialization=null)
 Initializes a FastFileClassCache instance.
string GetModelFilePath (object? id=null)
 Retrieves the complete file path for a model, optionally including the specified ID.
T? DeserializeCacheString< T > (string? content)
 Deserializes a cached string into an object of type T.
FastFileCacheRecordFetchFullRecord (string path)
 Retrieves a complete FastFileCacheRecord, loading content from the file if necessary, and keeps the cache updated.
string? FetchString (string path)
 Fetches the cached string content from a specified path.
Task< OpResponseFetch (RequestOp requestOp)
 Asynchronously fetches an object using a specified RequestOp, handling the operation depending on the verb.
async Task Setup ()
 Implement this for any setup required.
async Task Store (object id, object model, long arrivedAt)
 Stores a given model object identified by a specific id with a timestamp.
async Task StoreAll (IReadOnlyList< object > results, long arrivedAt)
async Task StoreCollection (string key, IEnumerable ids, long arrivedAt)
 Stores a collection of ids identified by a specific key with a timestamp.
async Task Remove (object id)
 Removes a model identified by a specific id from both the cache and the file system.
async Task ClearAll (bool exceptHeld, DateTime? olderThan=null)
 Clears all cached entries, optionally preserving specific entries based on held status or last-modified dates which can be older than a defined point-in-time.

Protected Member Functions

string GetModelPath (object? id=null)
 Retrieves the storage path of all models for the class, or one with the specified id.
string GetCollectionPath (string? key=null)
 Retrieves the storage path for all collections, or one with the given key.
string ToFilePath (string path)
 Transforms a given relative path into a full file path using the base directory.
string GetCollectionFilePath (string? key=null)
 Retrieves the complete file path for a collection, optionally including the specified key.
uint HashAnyString (string? s)
 Computes a hash from the given string using FNVHash algorithm.
void StoreString (string path, long timeMs, string content)
 Stores the given string in cache and writes it to a file while ensuring consistency with file operations in case of an update.
async Task SerializeToPathAsync (string aPath, object aObject, long timeMs)
 Asynchronously serializes an object to a specified path with a given timestamp.
async Task< T?> DeserializeFromPathAsync< T > (string aPath)
 Asynchronously deserializes content from a specified path into an object of type T.

Static Protected Attributes

const int MAX_STORED_LENGTH = 255

Properties

record FastFileCacheRecord
 Represents a memory record in the internal cache.
CascadeDataLayerCascade [get, set]
 CascadeDataLayer reference.

Detailed Description

Provides a file based IModelClassCache which stores serialized model classes and their collections in directory-based file storage. It uses hashing and memory storage to speed up some reads and writes.

Type Constraints
Model :class 

Member Function Documentation

◆ ClearAll()

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

Clears all cached entries, optionally preserving specific entries based on held status or last-modified dates which can be older than a defined point-in-time.

Parameters
exceptHeldIf true, preserves held models and collections.
olderThanOptional DateTime specifying the threshold for removal based on last-modified time.

Implements Buzzware.Cascade.IModelClassCache.

◆ DeserializeCacheString< T >()

T? Buzzware.Cascade.FastFileClassCache< Model, IdType >.DeserializeCacheString< T > ( string? content)
inline

Deserializes a cached string into an object of type T.

Template Parameters
TThe model type into which the string is deserialized.
Parameters
contentThe string content to be deserialized.
Returns
An instance of type T restored from the content, or default if content is null or empty.

◆ DeserializeFromPathAsync< T >()

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

Asynchronously deserializes content from a specified path into an object of type T.

Template Parameters
TThe model type into which the content should be deserialized.
Parameters
aPathPath from where the content is loaded for deserialization.
Returns
An instance of type T, or null if deserialization fails.

◆ FastFileClassCache()

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

Initializes a FastFileClassCache instance.

Parameters
fileDirThe directory path where model and collection files are stored.
serializationOptional Cascade JSON serializer - created internally if not provided

◆ Fetch()

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

Asynchronously fetches an object using a specified RequestOp, handling the operation depending on the verb.

Parameters
requestOpThe operation request defining the type, verb, and key/id for the fetch operation.
Returns
An OpResponse containing the result or indicating none found.

Implements Buzzware.Cascade.IModelClassCache.

◆ FetchFullRecord()

FastFileCacheRecord? Buzzware.Cascade.FastFileClassCache< Model, IdType >.FetchFullRecord ( string path)
inline

Retrieves a complete FastFileCacheRecord, loading content from the file if necessary, and keeps the cache updated.

Parameters
pathThe path for which the cache record is to be fetched.
Returns
A FastFileCacheRecord including content if loaded or already cached, or null if not found.

◆ FetchString()

string? Buzzware.Cascade.FastFileClassCache< Model, IdType >.FetchString ( string path)
inline

Fetches the cached string content from a specified path.

Parameters
pathThe path from which the content is retrieved.
Returns
The cached string content or null if not available.

◆ GetCollectionFilePath()

string Buzzware.Cascade.FastFileClassCache< Model, IdType >.GetCollectionFilePath ( string? key = null)
inlineprotected

Retrieves the complete file path for a collection, optionally including the specified key.

Parameters
keyOptional key to specify a specific collection file.
Returns
The full file path for a collection file.

◆ GetCollectionPath()

string Buzzware.Cascade.FastFileClassCache< Model, IdType >.GetCollectionPath ( string? key = null)
inlineprotected

Retrieves the storage path for all collections, or one with the given key.

Parameters
keyOptional key
Returns
The relative path

◆ GetModelFilePath()

string Buzzware.Cascade.FastFileClassCache< Model, IdType >.GetModelFilePath ( object? id = null)
inline

Retrieves the complete file path for a model, optionally including the specified ID.

Parameters
idOptional object ID to specify a specific model file.
Returns
The full file path for a model file.

◆ GetModelPath()

string Buzzware.Cascade.FastFileClassCache< Model, IdType >.GetModelPath ( object? id = null)
inlineprotected

Retrieves the storage path of all models for the class, or one with the specified id.

Parameters
idOptional object id to specify a specific model file.
Returns
the relative path

◆ HashAnyString()

uint Buzzware.Cascade.FastFileClassCache< Model, IdType >.HashAnyString ( string? s)
inlineprotected

Computes a hash from the given string using FNVHash algorithm.

Parameters
sInput string for which hash is to be computed.
Returns
A 32-bit unsigned integer representing the computed hash.

◆ Remove()

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

Removes a model identified by a specific id from both the cache and the file system.

Parameters
idThe identifier for the model to remove.

Implements Buzzware.Cascade.IModelClassCache.

◆ SerializeToPathAsync()

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

Asynchronously serializes an object to a specified path with a given timestamp.

Parameters
aPathThe destination path for storing the serialized object.
aObjectThe object to be serialized.
timeMsThe timestamp to associate with the serialized content.

◆ Setup()

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

Implement this for any setup required.

Returns

Implements Buzzware.Cascade.IModelClassCache.

◆ Store()

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

Stores a given model object identified by a specific id with a timestamp.

Parameters
idThe identifier for the model to be stored.
modelThe model object to be serialized and stored.
arrivedAtThe timestamp in milliseconds when the model arrived.

Implements Buzzware.Cascade.IModelClassCache.

◆ StoreAll()

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

◆ StoreCollection()

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

Stores a collection of ids identified by a specific key with a timestamp.

Parameters
keyThe key that identifies the collection to be stored.
idsThe collection of identifiers to store.
arrivedAtThe timestamp in milliseconds when the collection was established.

Implements Buzzware.Cascade.IModelClassCache.

◆ StoreString()

void Buzzware.Cascade.FastFileClassCache< Model, IdType >.StoreString ( string path,
long timeMs,
string content )
inlineprotected

Stores the given string in cache and writes it to a file while ensuring consistency with file operations in case of an update.

Parameters
pathRelative path of where to store the content.
timeMsTimestamp indicating when the content was received.
contentThe content string to store.

◆ ToFilePath()

string Buzzware.Cascade.FastFileClassCache< Model, IdType >.ToFilePath ( string path)
inlineprotected

Transforms a given relative path into a full file path using the base directory.

Parameters
pathRelative path to be combined with the base directory.
Returns
The complete file path.

Property Documentation

◆ Cascade

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

CascadeDataLayer reference.

Implements Buzzware.Cascade.IModelClassCache.


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