Interface ICacheTable<TKey>
Inherited Members
Namespace: NFX.ApplicationModel.Pile
Assembly: NFX.dll
Syntax
public interface ICacheTable<TKey> : ICacheTable, INamed
Type Parameters
Name | Description |
---|---|
TKey |
Properties
KeyComparer
Returns equality comparer for keys, or null to use default Equals
Declaration
IEqualityComparer<TKey> KeyComparer { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEqualityComparer<TKey> |
Methods
AsEnumerable(Boolean)
Returns the table as enumerable of entries with optional materialization of values (which is slower). Materialization is guaranteed to be consistent with the key
Declaration
IEnumerable<ICacheEntry<TKey>> AsEnumerable(bool withValues)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | withValues | True, to materialize internal PilePointers into CLR objects |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ICacheEntry<TKey>> |
ContainsKey(TKey, Int32)
Returns true if cache has object with the key, optionally filtering-out objects older than ageSec param if it is > zero. Returns false if there is no object with the specified key or it is older than ageSec limit.
Declaration
bool ContainsKey(TKey key, int ageSec = 0)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
System.Int32 | ageSec |
Returns
Type | Description |
---|---|
System.Boolean |
Get(TKey, Int32)
Gets cache object by key, optionally filtering-out objects older than ageSec param if it is > zero. Returns null if there is no object with the specified key or it is older than ageSec limit.
Declaration
object Get(TKey key, int ageSec = 0)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
System.Int32 | ageSec |
Returns
Type | Description |
---|---|
System.Object |
GetOrPut(TKey, Func<ICacheTable<TKey>, TKey, Object, Object>, Object, out Nullable<PutResult>, Int32, Int32, Int32, Nullable<DateTime>)
Atomically tries to get object by key if it exists, otherwise calls a factory method under lock and puts the data with the specified parameters. 'newPutResult' returns the result of the put after factory method call. Keep in mind, that even if a factory method created a new object, there may be a case when the value could not be physically inserted in the cache because of a collision (data with higher priority occupies space and space is capped), so check for 'newPutResult' value which is null in case of getting an existing item. Returns object that was gotten or created anew
Declaration
object GetOrPut(TKey key, Func<ICacheTable<TKey>, TKey, object, object> valueFactory, object factoryContext, out PutResult? newPutResult, int ageSec = 0, int putMaxAgeSec = 0, int putPriority = 0, DateTime? putAbsoluteExpirationUTC = default (DateTime? ))
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
System.Func<ICacheTable<TKey>, TKey, System.Object, System.Object> | valueFactory | |
System.Object | factoryContext | |
System.Nullable<PutResult> | newPutResult | |
System.Int32 | ageSec | |
System.Int32 | putMaxAgeSec | |
System.Int32 | putPriority | |
System.Nullable<System.DateTime> | putAbsoluteExpirationUTC |
Returns
Type | Description |
---|---|
System.Object |
GetPointer(TKey, Int32)
Gets cache object pointer by key, optionally filtering-out objects older than ageSec param if it is > zero. Returns invalid pointer if there is no object with the specified key or it is older than ageSec limit.
Declaration
PilePointer GetPointer(TKey key, int ageSec = 0)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
System.Int32 | ageSec |
Returns
Type | Description |
---|---|
PilePointer |
Put(TKey, Object, Nullable<Int32>, Int32, Nullable<DateTime>)
Puts an object identified by a key into cache returning the result of the put. For example, put may have added nothing if the table is capped and the space is occupied with data of higher priority
Declaration
PutResult Put(TKey key, object obj, int ? maxAgeSec = default (int ? ), int priority = 0, DateTime? absoluteExpirationUTC = default (DateTime? ))
Parameters
Type | Name | Description |
---|---|---|
TKey | key | A table-wide unique obvject key |
System.Object | obj | An object to put |
System.Nullable<System.Int32> | maxAgeSec | If null then the default maxAgeSec is taken from Options property, otherwise specifies the length of items life in seconds |
System.Int32 | priority | The priority of this item. If there is no space in future the items with lower priorities will not evict existing data with highr priorities |
System.Nullable<System.DateTime> | absoluteExpirationUTC | Optional UTC timestamp of object eviction from cache |
Returns
Type | Description |
---|---|
PutResult | The status of put - whether item was inserted/replaced(if key exists)/overwritten or collided with higher-prioritized existing data |
PutPointer(TKey, PilePointer, Nullable<Int32>, Int32, Nullable<DateTime>)
Puts a pointer identified by a key into cache returning the result of the put. For example, put may have added nothing if the table is capped and the space is occupied with data of higher priority
Declaration
PutResult PutPointer(TKey key, PilePointer ptr, int ? maxAgeSec = default (int ? ), int priority = 0, DateTime? absoluteExpirationUTC = default (DateTime? ))
Parameters
Type | Name | Description |
---|---|---|
TKey | key | A table-wide unique obvject key |
PilePointer | ptr | A valid pointer to put |
System.Nullable<System.Int32> | maxAgeSec | If null then the default maxAgeSec is taken from Options property, otherwise specifies the length of items life in seconds |
System.Int32 | priority | The priority of this item. If there is no space in future the items with lower priorities will not evict existing data with highr priorities |
System.Nullable<System.DateTime> | absoluteExpirationUTC | Optional UTC timestamp of object eviction from cache |
Returns
Type | Description |
---|---|
PutResult | The status of put - whether item was inserted/replaced(if key exists)/overwritten or collided with higher-prioritized existing data |
Rejuvenate(TKey)
Resets internal object age returning true of object was found and rejuvenated
Declaration
bool Rejuvenate(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key |
Returns
Type | Description |
---|---|
System.Boolean |
Remove(TKey)
Removes data by key returning true if found and removed
Declaration
bool Remove(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key |
Returns
Type | Description |
---|---|
System.Boolean |
SizeOfValue(TKey, Int32)
Returns the size of stored object if cache has object with the key, optionally filtering-out objects older than ageSec param if it is > zero.
Declaration
long SizeOfValue(TKey key, int ageSec = 0)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | |
System.Int32 | ageSec |
Returns
Type | Description |
---|---|
System.Int64 |