Interface IAppCacheService
Build-in persistent distributed cache. Key/Values are cached on each Firefly instance and synced with Lighthouse that persist them in AppDatabase. The build-in AppCache implementation also implements IDistributedCache. Both IAppCacheService and IDistributedCache are automatically added to the DI Services (Dependency Injection) and are available for use.
public interface IAppCacheService
Methods
AddOrUpdate(string, string, object?, GlowAppScope)
Add or update a key/value pair in the specified cache.
IAppCacheService.IAppCacheWriteBuilder AddOrUpdate(string cacheName, string key, object? value, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
key
stringThe cache-entry key to write
value
objectThe cache-entry value to write
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
AddOrUpdate(string, string, object?, CancellationToken, GlowAppScope)
Add or update a key/value pair in the specified cache.
IAppCacheService.IAppCacheWriteBuilder AddOrUpdate(string cacheName, string key, object? value, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
key
stringThe cache-entry key to write
value
objectThe cache-entry value to write
cancellationToken
CancellationTokenRequest write operation cancellation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
ClearAsync(string, CancellationToken, GlowAppScope)
Clear/Delete ALL entries in the cache.
Task<long> ClearAsync(string cacheName, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
ContainsAsync(string, string, CancellationToken, GlowAppScope)
Check if the cache contains an entry with the specified key.
Task<bool> ContainsAsync(string cacheName, string key, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
key
stringThe cache-entry key to use
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
IncrementAsync(string, string, long, CancellationToken, GlowAppScope)
Increment the Integer value in the cache.
Task IncrementAsync(string cacheName, string key, long byValue, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
key
stringThe cache-entry key to use
byValue
longThe value to be added to the existing cache entry
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
IncrementAsync(string, string, CancellationToken, GlowAppScope)
Increment the Integer value in the cache.
Task IncrementAsync(string cacheName, string key, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
key
stringThe cache-entry key to use
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
ListKeysAsync(string, CancellationToken, GlowAppScope)
List cache keys stored in the cache.
IAsyncEnumerable<string> ListKeysAsync(string cacheName, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
ReadAsync<TValue>(string, string, CancellationToken, GlowAppScope, object, bool, bool)
Get the value for the specified key in this cache.
Task<TValue> ReadAsync<TValue>(string cacheName, string key, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service, object serializerOptions = null, bool suppressExceptions = false, bool touch = true)
Parameters
cacheName
stringThe Cache
key
stringThe cache-entry key to use
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
serializerOptions
objectSpecial serialization options to use when deserializing object
suppressExceptions
boolreturn default(TValue) if entry was not found
touch
boolupdate sliding expiration
Returns
- Task<TValue>
Type Parameters
TValue
RefreshAsync(string, string, CancellationToken, GlowAppScope)
Refresh/Invalidate specific entry memory-cached value for the specified distributed cache.
Task RefreshAsync(string cacheName, string key, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
key
stringThe cache-entry key to use
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
RemoveAsync(string, string, CancellationToken, GlowAppScope)
Remove a specific entry from the cache.
Task<bool> RemoveAsync(string cacheName, string key, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
key
stringThe cache-entry key to use
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
TouchAsync(string, IEnumerable<string>, CancellationToken, GlowAppScope)
Reset sliding expiration to restart from Now.
Task TouchAsync(string cacheName, IEnumerable<string> keys, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
keys
IEnumerable<string>The cache-entry keys to touch
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
TouchAsync(string, string, CancellationToken, GlowAppScope)
Reset sliding expiration to restart from Now.
Task TouchAsync(string cacheName, string key, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)
Parameters
cacheName
stringThe Cache
key
stringThe cache-entry key to touch
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Returns
TryReadOrDefaultAsync<TValue>(string, string, CancellationToken, GlowAppScope, TValue, object, bool, bool)
Try to get the value for the specified key in this cache. If not found return Default value
Task<TValue> TryReadOrDefaultAsync<TValue>(string cacheName, string key, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service, TValue Default = default, object serializerOptions = null, bool suppressExceptions = false, bool touch = true)
Parameters
cacheName
stringThe Cache
key
stringThe cache-entry key to use
cancellationToken
CancellationTokenCancellation token for operation
scope
GlowAppScopeThe scope of the cache.
- QuantumSpace scope means the cache is shared with other services in the same QuantumSpace.
- Service scope means this cache is only visible to other instances of the same service.
Default
TValuethe value to return when entry not found
serializerOptions
objectSpecial serialization options to use when deserializing object
suppressExceptions
boolreturn default(TValue) if entry was not found
touch
boolupdate sliding expiration
Returns
- Task<TValue>
Type Parameters
TValue