Class CacheStoreUtilities
Provides utility methods for working with the data store and cache.
Inheritance
Inherited Members
Namespace: Terrasoft.Core.Store
Assembly: Terrasoft.Core.dll
Syntax
public static class CacheStoreUtilities
Methods
AdjustRawGetValuesResult(IEnumerable<String>, IDictionary<String, Object>)
Checks the passed dictionary with values for the presence in it of values with the given keys.
Declaration
public static IDictionary<string, object> AdjustRawGetValuesResult(IEnumerable<string> keys, IDictionary<string, object> rawGetValuesResult)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.String> | keys | The list of keys whose presence is checked in the |
System.Collections.Generic.IDictionary<System.String, System.Object> | rawGetValuesResult | A dictionary in which the presence of values with the |
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, System.Object> | A dictionary with values for the |
ExpireGroup(ICacheStore, String)
Sets the aging flag for the specified group of cache items.
Declaration
public static void ExpireGroup(this ICacheStore source, string groupName)
Parameters
Type | Name | Description |
---|---|---|
ICacheStore | source | Cache. |
System.String | groupName | Element group name. |
GetRootStore(ICacheStore)
Gets a root cache.
Declaration
public static ICacheStore GetRootStore(this ICacheStore source)
Parameters
Type | Name | Description |
---|---|---|
ICacheStore | source | Cache. |
Returns
Type | Description |
---|---|
ICacheStore | The root cache. |
Remarks
The method moves along a chain of proxy objects, starting from the source
, until it reaches the very first (root) cache.
GetRootStore(IDataStore)
Gets a root data storage.
Declaration
public static IDataStore GetRootStore(this IDataStore source)
Parameters
Type | Name | Description |
---|---|---|
IDataStore | source | Data storage. |
Returns
Type | Description |
---|---|
IDataStore | The root data storage. |
Remarks
The method moves along a chain of proxy objects, starting from the source
, until it reaches the very first (root) data storage.
GetValue<T>(IBaseStore, String)
Gets the value by the key
key from the data storage or cache and casts the obtained value to the specified type. The method returns null
if the key value is not found.
Declaration
public static T GetValue<T>(this IBaseStore source, string key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IBaseStore | source | Data storage or cache. |
System.String | key | Key of the value. |
Returns
Type | Description |
---|---|
T | The by the |
Type Parameters
Name | Description |
---|---|
T | The type to which the value returned from the storage / cache is given. |
GetValue<T>(IBaseStore, String, T)
Gets the value by the key
key from the data storage or cache and casts the obtained value to the specified type. If no key value is found, the method returns the specified default value.
Declaration
public static T GetValue<T>(this IBaseStore source, string key, T defaultValue)
Parameters
Type | Name | Description |
---|---|---|
IBaseStore | source | Data storage or cache. |
System.String | key | Key of the value. |
T | defaultValue | The default value that will be returned of the method if the value by key was not found in the storage/cache. |
Returns
Type | Description |
---|---|
T | The by the |
Type Parameters
Name | Description |
---|---|
T | The type to which the value returned from the storage / cache is given. |
GetValues(ICacheStore, String[])
Gets values from the cache according to a given list of keys.
Declaration
public static IDictionary<string, object> GetValues(this ICacheStore source, params string[] keys)
Parameters
Type | Name | Description |
---|---|---|
ICacheStore | source | Cache. |
System.String[] | keys | List of keys for which to obtain values |
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, System.Object> | The dictionary that contains the complete list of keys and values corresponding to these keys. If a value by a certain key was not found, the record in the dictionary will exist, but its value will be |
Pop<T>(IDataStore, String)
Gets the value by the key
key from the data storage, casts the obtained value to the appropriate type and deletes the given key from the storage
Declaration
public static T Pop<T>(this IDataStore source, string key)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataStore | source | Data storage. |
System.String | key | Key of the value. |
Returns
Type | Description |
---|---|
T | The by the |
Type Parameters
Name | Description |
---|---|
T | The type to which the value returned from the storage / data is given. |
SetOrRemoveValue(ICacheStore, String, Object)
Tries to write the value
value to the cache by the key
key. If the value
is null
, deletes the key from the cache
Declaration
public static void SetOrRemoveValue(this ICacheStore source, string key, object value)
Parameters
Type | Name | Description |
---|---|---|
ICacheStore | source | Cache. |
System.String | key | The key by which the |
System.Object | value | The value that is written to the cache by the |
WithLocalCaching(ICacheStore)
Applies local storage of data when working with the cache. Each item placed in the cache will have its own sign of relevance.
Declaration
public static ICacheStore WithLocalCaching(this ICacheStore source)
Parameters
Type | Name | Description |
---|---|---|
ICacheStore | source | Cache. |
Returns
Type | Description |
---|---|
ICacheStore | The cache wrapper that provides the local data storage and verifies data freshness in the initial cache. The freshness indicator is verified each time the entities are accessed. |
Remarks
It is recommended to be used only when working with a cache with relatively "expensive" access (for example, a cache with network access) and with significant amounts of cached items.
WithLocalCaching(ICacheStore, String)
Applies local storage of data when working with the cache.
Declaration
public static ICacheStore WithLocalCaching(this ICacheStore source, string groupName)
Parameters
Type | Name | Description |
---|---|---|
ICacheStore | source | Cache. |
System.String | groupName | The name for the group of freshness control items. All elements that are placed in this group will lose relevance when the ExpireGroup(ICacheStore, String) method is called. |
Returns
Type | Description |
---|---|
ICacheStore | The cache wrapper that provides the local data storage and verifies data freshness in the initial cache. The freshness indicator is verified each time the entities are accessed. |
Remarks
It is recommended to be used only when working with a cache with relatively "expensive" access (for example, a cache with network access) and with significant amounts of cached items.
WithLocalCachingOnly(ICacheStore, String, Boolean)
Provides the local data storage and data freshness monitoring , using the specified (global) cache.
Declaration
public static ICacheStore WithLocalCachingOnly(this ICacheStore source, string groupName, bool ignoreUserIdentity = false)
Parameters
Type | Name | Description |
---|---|---|
ICacheStore | source | Cache. |
System.String | groupName | The name for the group of freshness control items. All elements that are placed in this group will lose relevance when the ExpireGroup(ICacheStore, String) method is called. |
System.Boolean | ignoreUserIdentity | A flag of the participation of the name of the current user in the formation of the cache access key. |
Returns
Type | Description |
---|---|
ICacheStore | The cache wrapper that provides the local data storage and verifies data freshness in the initial cache. The freshness indicator is verified each time the entities are accessed. |
Remarks
The data is not passed to a cache – it only verifies the freshness indicator. Items in the local cache lose relevance only when the ExpireGroup(ICacheStore, String) method is called, but not when writing a new object to the cache.
Exceptions
Type | Condition |
---|---|
System.ArgumentException | If an empty string or |