Table of Contents

Interface IAppCacheService

Namespace
Phoesion.Glow.SDK.Firefly
Assembly
Phoesion.Glow.SDK.Firefly.Abstractions.dll

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 string

The Cache

key string

The cache-entry key to write

value object

The cache-entry value to write

scope GlowAppScope

The 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

IAppCacheService.IAppCacheWriteBuilder

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 string

The Cache

key string

The cache-entry key to write

value object

The cache-entry value to write

cancellationToken CancellationToken

Request write operation cancellation

scope GlowAppScope

The 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

IAppCacheService.IAppCacheWriteBuilder

ClearAsync(string, CancellationToken, GlowAppScope)

Clear/Delete ALL entries in the cache.

Task<long> ClearAsync(string cacheName, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)

Parameters

cacheName string

The Cache

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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

Task<long>

Number of entries deleted

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 string

The Cache

key string

The cache-entry key to use

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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

Task<bool>

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 string

The Cache

key string

The cache-entry key to use

byValue long

The value to be added to the existing cache entry

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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

Task

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 string

The Cache

key string

The cache-entry key to use

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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

Task

ListKeysAsync(string, CancellationToken, GlowAppScope)

List cache keys stored in the cache.

IAsyncEnumerable<string> ListKeysAsync(string cacheName, CancellationToken cancellationToken, GlowAppScope scope = GlowAppScope.Service)

Parameters

cacheName string

The Cache

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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

IAsyncEnumerable<string>

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 string

The Cache

key string

The cache-entry key to use

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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 object

Special serialization options to use when deserializing object

suppressExceptions bool

return default(TValue) if entry was not found

touch bool

update 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 string

The Cache

key string

The cache-entry key to use

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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

Task

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 string

The Cache

key string

The cache-entry key to use

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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

Task<bool>

Returns true id an item was actually removed. False if no item was found for removal

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 string

The Cache

keys IEnumerable<string>

The cache-entry keys to touch

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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

Task

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 string

The Cache

key string

The cache-entry key to touch

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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

Task

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 string

The Cache

key string

The cache-entry key to use

cancellationToken CancellationToken

Cancellation token for operation

scope GlowAppScope

The 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 TValue

the value to return when entry not found

serializerOptions object

Special serialization options to use when deserializing object

suppressExceptions bool

return default(TValue) if entry was not found

touch bool

update sliding expiration

Returns

Task<TValue>

Type Parameters

TValue