Interface ICacheService
Experimental! Cache service to help your code cache data.
It does quite a bit of magic, for example:
- scope the cache to the current App, so a key "data" will not bleed to other apps
- change the key when the data is for the current user only
- ...and more.
It's not yet fully documented.
[InternalApi_DoNotUse_MayChangeWithoutNotice]
public interface ICacheService
Remarks
Basic use will just use a string key. The internal key will be more complex, while advanced use would first create the specs using CreateSpecs(string, NoParamOrder, string, bool?) and then use those specs for all operations. To be Released ca. v19.01
Methods
Contains(string)
Check if the cache contains data for the given key.
bool Contains(string key)
Parameters
key
string
Returns
Contains(ICacheSpecs)
Check if the cache contains data for the given specs.
bool Contains(ICacheSpecs specs)
Parameters
specs
ICacheSpecs
Returns
Contains<T>(string)
Check if the cache contains data of specified type for the given key.
bool Contains<T>(string key)
Parameters
key
string
Returns
Type Parameters
T
Contains<T>(ICacheSpecs)
Check if the cache contains data of specified type for the given specs.
bool Contains<T>(ICacheSpecs specs)
Parameters
specs
ICacheSpecs
Returns
Type Parameters
T
CreateSpecs(string, NoParamOrder, string, bool?)
Create cache specs for a specific key and optional segment.
This is used for complex setups where the same specs will be reused for multiple operations.
ICacheSpecs CreateSpecs(string key, NoParamOrder protector = default, string regionName = null, bool? shared = null)
Parameters
key
stringThe main cache key (name) to use. It will be extended internally, to prevent collisions, so it can be fairly short.
protector
NoParamOrderregionName
stringa cache region to segment the cache into multiple regions
shared
bool?If set to
true
it will make this key available on other apps which access the data with allApps =true
. By default, each app has its own region, preventing key collisions between apps.
Returns
GetOrSet<T>(string, NoParamOrder, Func<T>)
Get or set data in the cache for the given key, with optional generation and specs-tweaking.
T GetOrSet<T>(string key, NoParamOrder protector = default, Func<T> generate = null)
Parameters
key
stringprotector
NoParamOrdergenerate
Func<T>
Returns
- T
Type Parameters
T
GetOrSet<T>(ICacheSpecs, NoParamOrder, Func<T>)
Get or set data in the cache for the given specs, with optional generation.
T GetOrSet<T>(ICacheSpecs specs, NoParamOrder protector = default, Func<T> generate = null)
Parameters
specs
ICacheSpecsprotector
NoParamOrdergenerate
Func<T>
Returns
- T
Type Parameters
T
Get<T>(string, NoParamOrder, T)
Get data from the cache of the given type for the given key, with optional fallback.
T Get<T>(string key, NoParamOrder protector = default, T fallback = default)
Parameters
key
stringprotector
NoParamOrderfallback
T
Returns
- T
Type Parameters
T
Get<T>(ICacheSpecs, NoParamOrder, T)
Get data from the cache of the given type for the given specs, with optional fallback.
T Get<T>(ICacheSpecs specs, NoParamOrder protector = default, T fallback = default)
Parameters
specs
ICacheSpecsprotector
NoParamOrderfallback
T
Returns
- T
Type Parameters
T
Remove(string)
Remove a cache entry.
object Remove(string key)
Parameters
key
string
Returns
- object
The object if it was in the cache, otherwise null.
Remove(ICacheSpecs)
Remove a cache entry.
object Remove(ICacheSpecs key)
Parameters
key
ICacheSpecs
Returns
- object
The object if it was in the cache, otherwise null.
Set<T>(string, T, NoParamOrder)
Set a value in the cache.
void Set<T>(string key, T value, NoParamOrder protector = default)
Parameters
key
stringvalue
Tprotector
NoParamOrder
Type Parameters
T
Set<T>(ICacheSpecs, T, NoParamOrder)
Set a value in the cache.
void Set<T>(ICacheSpecs specs, T value, NoParamOrder protector = default)
Parameters
specs
ICacheSpecsvalue
Tprotector
NoParamOrder
Type Parameters
T
TryGet<T>(string, out T)
Try to get data of the specified type from the cache for the given key.
bool TryGet<T>(string key, out T value)
Parameters
key
stringvalue
T
Returns
- bool
true
if found,false
if not found
Type Parameters
T
TryGet<T>(ICacheSpecs, out T)
Try to get data of the specified type from the cache for the given specs.
bool TryGet<T>(ICacheSpecs specs, out T value)
Parameters
specs
ICacheSpecsvalue
T
Returns
- bool
true
if found,false
if not found
Type Parameters
T