Class ComplexKeyHashingStrategy
Provides hashing strategy for keys that are not scalar uint64.
This is a companion class for CacheStore which only understands uint64 as keys for efficiency purposes.
One may extend this class to implement custom resolution of complex keys into uint64 hashes
and provide collision handling. The base implementation uses object.GetHashCode() with chaining for collision resolution
Inheritance
System.Object
ComplexKeyHashingStrategy
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: Azos.dll
Syntax
public class ComplexKeyHashingStrategy
Constructors
ComplexKeyHashingStrategy(CacheStore)
Declaration
public ComplexKeyHashingStrategy(CacheStore store)
Parameters
Fields
MAX_CACHE_CHAIN_LENGTH
How many times hash will be adjusted while chaining
Declaration
public const int MAX_CACHE_CHAIN_LENGTH = 5
Field Value
Type |
Description |
System.Int32 |
|
Store
References cachestore that this strategy works with
Declaration
public readonly CacheStore Store
Field Value
Methods
ComplexKeyToCacheKey(Object)
Override to convert complex object to uint64 key.
The default implementation returns DefaultComplexKeyToCacheKey(key)
Declaration
public virtual ulong ComplexKeyToCacheKey(object key)
Parameters
Type |
Name |
Description |
System.Object |
key |
|
Returns
Type |
Description |
System.UInt64 |
|
DefaultComplexKeyToCacheKey(Object)
Default implementation that converts complex object to uint64 key.
The default implementation returns the hashcode of the object unless the key is string
in which case it calls DefaultStringKeyToCacheKey() or IULongHashProvider(GDID and parcels).
The function is not deterministic due to the use of .GetHashCode() that may change between release for some objects (depends on object implementation),
so the returned value should not be persisted
Declaration
public static ulong DefaultComplexKeyToCacheKey(object key)
Parameters
Type |
Name |
Description |
System.Object |
key |
|
Returns
Type |
Description |
System.UInt64 |
|
DefaultStringKeyToCacheKey(String)
Provides default implementation for converting string keys into uint64 hash.
This functions provides the best selectivity for strings that are 8 chars long or less.
The function is NOT deterministic as it uses .GetHashCode(), so the returned value should not be persisted
Declaration
public static ulong DefaultStringKeyToCacheKey(string key)
Parameters
Type |
Name |
Description |
System.String |
key |
|
Returns
Type |
Description |
System.UInt64 |
|
Get(String, Object, Int32)
Override to get a value keyed on a non-uint64 scalar from cache. Returns null when item does not exist
Declaration
public virtual object Get(string tableName, object key, int ageSec = 0)
Parameters
Type |
Name |
Description |
System.String |
tableName |
|
System.Object |
key |
|
System.Int32 |
ageSec |
|
Returns
Type |
Description |
System.Object |
|
Put(String, Object, Object, Int32, Int32, Nullable<DateTime>)
Override to put a value keyed on a non-uint64 scalar into cache. Returns table.Put() result
Declaration
public virtual bool Put(string tableName, object key, object value, int maxAgeSec = 0, int priority = 0, DateTime? absoluteExpirationUTC = default(DateTime? ))
Parameters
Type |
Name |
Description |
System.String |
tableName |
|
System.Object |
key |
|
System.Object |
value |
|
System.Int32 |
maxAgeSec |
|
System.Int32 |
priority |
|
System.Nullable<System.DateTime> |
absoluteExpirationUTC |
|
Returns
Type |
Description |
System.Boolean |
|
Remove(String, Object)
Override to remove an item keyed on a non-uint64 scalar from cache. Returns true if remove found and removed item from table
Declaration
public virtual bool Remove(string tableName, object key)
Parameters
Type |
Name |
Description |
System.String |
tableName |
|
System.Object |
key |
|
Returns
Type |
Description |
System.Boolean |
|
Extension Methods