Show / Hide Table of Contents

Class CacheBase

Base class for caches.

Inheritance
Object
CacheBase
MDOListTableCache
MDOPreferenceCache
PriceListCache
RedLetterDayCache
RowCacheBase<Row>
StatusMonitorCache
TravelCurrentCache
AddressFormatCache
CountryCache
LanguageInfoCache
EjCategoryCache
ErpConnectionAccessCache
FunctionRightCache
OwnerContactCache
Sentry.DataRightCache
Implements
IDisposable
IFlushable
Inherited Members
Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Namespace: SuperOffice.Data.Cache
Assembly: SoDataBase.dll
Syntax
public abstract class CacheBase : IDisposable, IFlushable
Remarks

Implement this class if you want to implement a cache within NetServer. Classes implementing this class should always be instantiated with the GetCache(Type) method.

The OnFlush() and OnRefresh() methods needs to be implemented by all classes implementing the cache.

Constructors

CacheBase(String, CacheType, Int32)

Default constructor for CacheBase

Declaration
protected CacheBase(string name, CacheType cacheType, int timeout)
Parameters
Type Name Description
String name

Name of the cache.

CacheType cacheType

Type of cache.

Int32 timeout

Timeout in [s] for the cache to expire.

Remarks

Classes inheriting this class should only be instantiated through the SoCache.GetCache method

Exceptions
Type Condition
SecurityException

This exception will be thrown if not above elements in the call stack is saved with the SuperOffice strong name.

Fields

_cacheState

Current state of the cache.

Declaration
protected CacheBase.CacheState _cacheState
Field Value
Type Description
CacheBase.CacheState

_lastUpdated

Time when the cache was last updated.

Declaration
protected DateTime _lastUpdated
Field Value
Type Description
DateTime

Properties

CacheType

Type of cache

Declaration
public CacheType CacheType { get; }
Property Value
Type Description
CacheType

IsValid

Check if the data in the cache is valid.

Declaration
public virtual bool IsValid { get; }
Property Value
Type Description
Boolean
Remarks

Default behavior is to verify that the time has not expired. If the time-out is 0, false will always be returned. if time-out is less than 0, true will always be returned.

When overriding this property, false should always be returned if _cacheState is different from Normal. If the cache is not valid, the _cacheState should be set to Expired prior to returning false.

Lock

Declaration
protected ReaderWriterLock Lock { get; }
Property Value
Type Description
ReaderWriterLock

Name

Name of the cache

Declaration
public string Name { get; }
Property Value
Type Description
String

State

State of the cache.

Declaration
public CacheBase.CacheState State { get; }
Property Value
Type Description
CacheBase.CacheState

Timeout

Timeout in [ms] for the cache to expire.

Declaration
public int Timeout { get; }
Property Value
Type Description
Int32

Methods

Dispose()

Dispose of the cache

Declaration
public void Dispose()
Remarks

A call to this method will cause a consequent call to Flush().

Flush()

Force the cache to be emptied.

Declaration
public void Flush()
Remarks

All memory used for caching should be "freed", by the consequent call to OnFlush().

GetCachedTableNumbers()

Implement in derived classes to declare what tables the cache is covering.

Declaration
public abstract int[] GetCachedTableNumbers()
Returns
Type Description
Int32[]

List of tables covered by the cache.

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

OnDisposed()

Method called when the cache is disposed.

Declaration
protected void OnDisposed()

OnExpired()

Method called when the cache has expired.

Declaration
protected void OnExpired()

OnFlush()

Flush data in the cache.

Declaration
protected abstract void OnFlush()
Remarks

Removing reference to all the data in the cache so the garbage collector can free up the memory.

OnFlushed()

Method called when the cache is flushed.

Declaration
protected void OnFlushed()

OnRefresh()

Refresh data in the cache.

Declaration
protected abstract void OnRefresh()

OnRefreshed()

Method called when the cache is refreshed.

Declaration
protected void OnRefreshed()

Refresh()

Force the cache to be refreshed

Declaration
public void Refresh()
Remarks

All invalid data in the cache should be removed, by the consequent call to OnRefresh().

Validate()

Validate the cache.

Declaration
public void Validate()
Remarks

Properties and methods returning data from the cache should call this method prior to accessing any of the data in the cache.

The implementation of the method forces a Refresh() if the data is not valid (e.g. not IsValid).

Events

Disposed

Event fired when the cache has been disposed;

Declaration
public event CacheEventHandler Disposed
Event Type
Type Description
CacheEventHandler

Expired

Event fired when the flush has expired.

Declaration
public event CacheEventHandler Expired
Event Type
Type Description
CacheEventHandler

Flushed

Event fired when the cache has been flushed (e.g. emptied);

Declaration
public event CacheEventHandler Flushed
Event Type
Type Description
CacheEventHandler

Refreshed

Event fired when the cache has been refreshed.

Declaration
public event CacheEventHandler Refreshed
Event Type
Type Description
CacheEventHandler
Remarks

Refreshing the cache does not necesearly mean that all the data is loaded back in the cache.

Implements

System.IDisposable
IFlushable

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top