DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Static Public Member Functions | Protected Member Functions | Properties | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Deveel.Data.Caching.Cache Class Referenceabstract

Represents a cache of Objects. /summary> More...

Inheritance diagram for Deveel.Data.Caching.Cache:
Deveel.Data.Caching.ICache Deveel.Data.Caching.CacheAdapter Deveel.Data.Caching.MemoryCache Deveel.Data.Caching.TableCellCache.Cache Deveel.Data.Caching.TableCellCache.Cache Deveel.Data.Caching.SizeLimitedCache

Public Member Functions

bool Set (object key, object value)
 Puts an object into the cache with the given key. More...
 
bool TryGet (object key, out object value)
 Tries to get an object for the given key from the underlying cache system. More...
 
object Remove (Object key)
 Removes a node for the given key from the cache. More...
 
virtual void Clear ()
 Clear the cache of all the entries. More...
 
void Dispose ()
 
- Public Member Functions inherited from Deveel.Data.Caching.ICache
object Remove (object key)
 Removes an object from the cache. More...
 

Static Public Member Functions

static int ClosestPrime (int value)
 

Protected Member Functions

 Cache ()
 
virtual void CheckClean ()
 This is called whenever at object is put into the cache. More...
 
virtual bool WipeMoreNodes ()
 Checks if the clean-up method should clean up more elements from the cache. More...
 
virtual void OnWipingNode (object value)
 Notifies that the given object has been wiped from the cache by the clean up procedure. More...
 
virtual void OnObjectAdded (object key, object value)
 Notifies that the given object and key has been added to the cache. More...
 
virtual void OnObjectRemoved (object key, Object value)
 Notifies that the given object and key has been removed from the cache. More...
 
virtual void OnAllCleared ()
 Notifies that the cache has been entirely cleared of all elements. More...
 
virtual void OnGetWalks (long totalWalks, long totalGetOps)
 Notifies that some statistical information about the hash map has updated. More...
 
abstract bool SetObject (object key, object value)
 When overridden in a derived class, it sets the value for the key given. More...
 
abstract bool TryGetObject (object key, out object value)
 
abstract object RemoveObject (object key)
 
virtual int Clean ()
 Cleans away some old elements in the cache. More...
 
virtual void Dispose (bool disposing)
 

Properties

virtual int NodeCount [get]
 Gets the number of nodes that are currently being stored in the cache. More...
 

Private Member Functions

 ~Cache ()
 

Private Attributes

int currentCacheSize
 The current cache size. More...
 
readonly int wipeTo
 The number of nodes that should be left available when the cache becomes too full and a clean up operation occurs. More...
 

Static Private Attributes

static readonly int[] PrimeList
 A list of primes ordered from lowest to highest. More...
 

Detailed Description

Represents a cache of Objects. /summary>

Definition at line 25 of file Cache.cs.

Constructor & Destructor Documentation

Deveel.Data.Caching.Cache.Cache ( )
inlineprotected

Definition at line 37 of file Cache.cs.

37  {
38  }
Deveel.Data.Caching.Cache.~Cache ( )
inlineprivate

Definition at line 41 of file Cache.cs.

41  {
42  Dispose(false);
43  }

Member Function Documentation

virtual void Deveel.Data.Caching.Cache.CheckClean ( )
inlineprotectedvirtual

This is called whenever at object is put into the cache.

This method should determine if the cache should be cleaned and call the clean method if appropriate.

Reimplemented in Deveel.Data.Caching.TableCellCache.Cache, Deveel.Data.Caching.TableCellCache.Cache, and Deveel.Data.Caching.SizeLimitedCache.

Definition at line 52 of file Cache.cs.

52  {
53  }
virtual int Deveel.Data.Caching.Cache.Clean ( )
inlineprotectedvirtual

Cleans away some old elements in the cache.

This method walks from the end, back wipe count elements putting each object on the recycle stack.

Returns
Returns the number entries that were cleaned.

summary> Gets the closest prime number to the one specified. /summary> param name="value">The integer value to which the returned integer has to be close.

returns>

Definition at line 204 of file Cache.cs.

virtual void Deveel.Data.Caching.Cache.Clear ( )
inlinevirtual

Clear the cache of all the entries.

Implements Deveel.Data.Caching.ICache.

Reimplemented in Deveel.Data.Caching.MemoryCache, and Deveel.Data.Caching.CacheAdapter.

Definition at line 190 of file Cache.cs.

190  {
191  OnAllCleared();
192  }
virtual void OnAllCleared()
Notifies that the cache has been entirely cleared of all elements.
Definition: Cache.cs:97
static int Deveel.Data.Caching.Cache.ClosestPrime ( int  value)
inlinestatic

Definition at line 214 of file Cache.cs.

214  {
215  for (int i = 0; i < PrimeList.Length; ++i) {
216  if (PrimeList[i] >= value) {
217  return PrimeList[i];
218  }
219  }
220  // Return the last prime
221  return PrimeList[PrimeList.Length - 1];
222  }
static readonly int[] PrimeList
A list of primes ordered from lowest to highest.
Definition: Cache.cs:227
void Deveel.Data.Caching.Cache.Dispose ( )
inline

Definition at line 270 of file Cache.cs.

270  {
271  Dispose(true);
272  GC.SuppressFinalize(this);
273  }
virtual void Deveel.Data.Caching.Cache.Dispose ( bool  disposing)
inlineprotectedvirtual

Reimplemented in Deveel.Data.Caching.MemoryCache.

Definition at line 275 of file Cache.cs.

275  {
276  if (disposing) {
277  Clear();
278  }
279  }
virtual void Clear()
Clear the cache of all the entries.
Definition: Cache.cs:190
virtual void Deveel.Data.Caching.Cache.OnAllCleared ( )
inlineprotectedvirtual

Notifies that the cache has been entirely cleared of all elements.

Definition at line 97 of file Cache.cs.

97  {
98  currentCacheSize = 0;
99  }
int currentCacheSize
The current cache size.
Definition: Cache.cs:29
virtual void Deveel.Data.Caching.Cache.OnGetWalks ( long  totalWalks,
long  totalGetOps 
)
inlineprotectedvirtual

Notifies that some statistical information about the hash map has updated.

Parameters
totalWalks
totalGetOps

This should be used to compile statistical information about the number of walks a get operation takes to retreive an entry from the hash.

This method is called every 8192 gets.

Reimplemented in Deveel.Data.Caching.TableCellCache.Cache, and Deveel.Data.Caching.TableCellCache.Cache.

Definition at line 115 of file Cache.cs.

115  {
116  }
virtual void Deveel.Data.Caching.Cache.OnObjectAdded ( object  key,
object  value 
)
inlineprotectedvirtual

Notifies that the given object and key has been added to the cache.

Parameters
key
value

Definition at line 81 of file Cache.cs.

81  {
83  }
int currentCacheSize
The current cache size.
Definition: Cache.cs:29
virtual void Deveel.Data.Caching.Cache.OnObjectRemoved ( object  key,
Object  value 
)
inlineprotectedvirtual

Notifies that the given object and key has been removed from the cache.

Parameters
key
value

Definition at line 90 of file Cache.cs.

90  {
92  }
int currentCacheSize
The current cache size.
Definition: Cache.cs:29
virtual void Deveel.Data.Caching.Cache.OnWipingNode ( object  value)
inlineprotectedvirtual

Notifies that the given object has been wiped from the cache by the clean up procedure.

Parameters
valueThe node value being wiped.

Reimplemented in Deveel.Data.Caching.TableCellCache.Cache, and Deveel.Data.Caching.TableCellCache.Cache.

Definition at line 73 of file Cache.cs.

73  {
74  }
object Deveel.Data.Caching.Cache.Remove ( Object  key)
inline

Removes a node for the given key from the cache.

Parameters
key

This is useful for ensuring the cache does not contain out-dated information.

Returns
Returns the value of the removed node or null if none was found for the given key.

Definition at line 178 of file Cache.cs.

178  {
179  object obj = RemoveObject(key);
180 
181  if (obj != null)
182  OnObjectRemoved(key, obj);
183 
184  return obj;
185  }
virtual void OnObjectRemoved(object key, Object value)
Notifies that the given object and key has been removed from the cache.
Definition: Cache.cs:90
abstract object RemoveObject(object key)
abstract object Deveel.Data.Caching.Cache.RemoveObject ( object  key)
protectedpure virtual
bool Deveel.Data.Caching.Cache.Set ( object  key,
object  value 
)
inline

Puts an object into the cache with the given key.

Parameters
keyThe key used to store the object.
valueThe object to add to the cache.

Implements Deveel.Data.Caching.ICache.

Definition at line 150 of file Cache.cs.

150  {
151 
152  // Do we need to clean any cache elements out?
153  CheckClean();
154 
155  bool newValue = SetObject(key, value);
156  if (newValue)
157  OnObjectAdded(key, value);
158 
159  return newValue;
160  }
abstract bool SetObject(object key, object value)
When overridden in a derived class, it sets the value for the key given.
virtual void OnObjectAdded(object key, object value)
Notifies that the given object and key has been added to the cache.
Definition: Cache.cs:81
virtual void CheckClean()
This is called whenever at object is put into the cache.
Definition: Cache.cs:52
abstract bool Deveel.Data.Caching.Cache.SetObject ( object  key,
object  value 
)
protectedpure virtual

When overridden in a derived class, it sets the value for the key given.

Parameters
keyThe key corresponding to the value to set.
valuethe value to set into the cache.
Returns
Returns false if the key existed and the value was set or otherwise true if the key was not found and the value was added to the cache.

Implemented in Deveel.Data.Caching.MemoryCache, and Deveel.Data.Caching.CacheAdapter.

bool Deveel.Data.Caching.Cache.TryGet ( object  key,
out object  value 
)
inline

Tries to get an object for the given key from the underlying cache system.

Parameters
keyThe key of the object to return.
valueThe value corresponding to the provided key, obtained from the underlying cache. This value can also be null if it was not possible to find the key given in the cache.
Returns
Returns true if the corresponding key was found in the underlying cache, otherwise false.

Implements Deveel.Data.Caching.ICache.

Definition at line 162 of file Cache.cs.

162  {
163  return TryGetObject(key, out value);
164  }
abstract bool TryGetObject(object key, out object value)
abstract bool Deveel.Data.Caching.Cache.TryGetObject ( object  key,
out object  value 
)
protectedpure virtual
virtual bool Deveel.Data.Caching.Cache.WipeMoreNodes ( )
inlineprotectedvirtual

Checks if the clean-up method should clean up more elements from the cache.

Returns
Returns true if the clean-up method that periodically cleans up the cache should clean up more elements from the cache, otherwise false.

Reimplemented in Deveel.Data.Caching.TableCellCache.Cache, and Deveel.Data.Caching.TableCellCache.Cache.

Definition at line 64 of file Cache.cs.

64  {
65  return (currentCacheSize >= wipeTo);
66  }
int currentCacheSize
The current cache size.
Definition: Cache.cs:29
readonly int wipeTo
The number of nodes that should be left available when the cache becomes too full and a clean up oper...
Definition: Cache.cs:35

Member Data Documentation

int Deveel.Data.Caching.Cache.currentCacheSize
private

The current cache size.

Definition at line 29 of file Cache.cs.

readonly int [] Deveel.Data.Caching.Cache.PrimeList
staticprivate

A list of primes ordered from lowest to highest.

Definition at line 227 of file Cache.cs.

readonly int Deveel.Data.Caching.Cache.wipeTo
private

The number of nodes that should be left available when the cache becomes too full and a clean up operation occurs.

Definition at line 35 of file Cache.cs.

Property Documentation

virtual int Deveel.Data.Caching.Cache.NodeCount
get

Gets the number of nodes that are currently being stored in the cache.

Definition at line 125 of file Cache.cs.


The documentation for this class was generated from the following file: