Class XCacheBase
Base class for all caches. Implementers must also use the CacheAttribute to declare timeout and optionally the Instance container name
Inheritance
Implements
Inherited Members
Namespace: SuperOffice.Data.Cache
Assembly: SoDataBase.dll
Syntax
public abstract class XCacheBase : IFlushable
Constructors
XCacheBase()
Constructor - retrieve values from attribute, subscribe to soft triggers and to global flush event
Declaration
protected XCacheBase()
Properties
LastTouch
When was this cache last touched (used, not created)
Declaration
public DateTime LastTouch { get; }
Property Value
Type | Description |
---|---|
DateTime |
Timeout
Cache timeout in seconds; caches are recreated if they have been unused for more than this time
Declaration
public int Timeout { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Flush()
Flush the cache: the next call to GetCurrent will retrieve a newly-created and initialized instance, instead of an existing cached one
Declaration
public void Flush()
GetCacheAttribute(Type)
Get the CacheAttribute that the derived class is decorated with
Declaration
public static CacheAttribute GetCacheAttribute(Type concreteCache)
Parameters
Type | Name | Description |
---|---|---|
Type | concreteCache |
Returns
Type | Description |
---|---|
CacheAttribute |
GetCachedTableNumbers()
Implement in derived classes to declare what tables the cache is covering. Return an empty array if no automatic flushing is wanted (why not??)
Declaration
public abstract int[] GetCachedTableNumbers()
Returns
Type | Description |
---|---|
Int32[] | List of tables covered by the cache. |
GetCurrentInstance<CacheType>()
Return the current instance of the cache
Declaration
protected static CacheType GetCurrentInstance<CacheType>()
where CacheType : XCacheBase
Returns
Type | Description |
---|---|
CacheType | Populated instance that can be used |
Type Parameters
Name | Description |
---|---|
CacheType | The concrete cache to return |
Remarks
We rely on the InjectionFactory system to keep the singleton instance (using the correct kind of container). Retrieval of that instance is straight-forward - the factory will either have one for us, or create one on the fly.
To bootstrap the process, if the factory does not have any binding for the concrete cache then we need to inspect its attribute to determine the correct instance container and timeout values. We can then set up the binding.
Once an instance has been retrieved, we need to inspect it for a possible timeout. If it is out of date then we tell the factory to forget the instance, and ask it for a new one.
IsCacheInvalidated(Int32, SqlType, Int32)
Determine if the change made the cache invalid.
Declaration
protected virtual bool IsCacheInvalidated(int tableNumber, SqlType sqlType, int primaryKey)
Parameters
Type | Name | Description |
---|---|---|
Int32 | tableNumber | Number of Table that is modified. |
SqlType | sqlType | Type of change (i.e. Insert, Update or Delete) |
Int32 | primaryKey | Primary key of the record being changed. |
Returns
Type | Description |
---|---|
Boolean |
Remarks
By default, any change to a cached table will cause invalidation, but a cache may have a more discerning opinion; if so then implement this method.