DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Classes | Public Member Functions | Protected Member Functions | Properties | Private Attributes | List of all members
Deveel.Data.Caching.MemoryCache Class Reference
Inheritance diagram for Deveel.Data.Caching.MemoryCache:
Deveel.Data.Caching.Cache Deveel.Data.Caching.ICache Deveel.Data.Caching.SizeLimitedCache

Classes

class  CacheValue
 

Public Member Functions

 MemoryCache ()
 
override void Clear ()
 Clear the cache of all the entries. More...
 
- Public Member Functions inherited from Deveel.Data.Caching.Cache
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...
 
void Dispose ()
 
- Public Member Functions inherited from Deveel.Data.Caching.ICache
object Remove (object key)
 Removes an object from the cache. More...
 

Protected Member Functions

virtual void UpdateElementAccess (object key, CacheValue cacheValue)
 
virtual CacheValue GetCacheValueUnlocked (object key)
 
virtual CacheValue SetValueUnlocked (object key, object value)
 
object RemoveUnlocked (object key)
 
override bool SetObject (object key, object value)
 When overridden in a derived class, it sets the value for the key given. More...
 
override bool TryGetObject (object key, out object value)
 
override object RemoveObject (object key)
 
override void Dispose (bool disposing)
 
- Protected Member Functions inherited from Deveel.Data.Caching.Cache
 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...
 
virtual int Clean ()
 Cleans away some old elements in the cache. More...
 

Properties

LinkedList< KeyValuePair< object, CacheValue > > IndexList [get, private set]
 
- Properties inherited from Deveel.Data.Caching.Cache
virtual int NodeCount [get]
 Gets the number of nodes that are currently being stored in the cache. More...
 

Private Attributes

readonly Dictionary< object, CacheValuevalueCache = new Dictionary<object, CacheValue>()
 
readonly object syncRoot = new object()
 
DateTime lastCacheAccess = DateTime.MaxValue
 
long totalGets = 0
 
long getTotal = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from Deveel.Data.Caching.Cache
static int ClosestPrime (int value)
 

Detailed Description

Definition at line 21 of file MemoryCache.cs.

Constructor & Destructor Documentation

Deveel.Data.Caching.MemoryCache.MemoryCache ( )
inline

Definition at line 29 of file MemoryCache.cs.

29  {
30  IndexList = new LinkedList<KeyValuePair<object, CacheValue>>();
31  }
LinkedList< KeyValuePair< object, CacheValue > > IndexList
Definition: MemoryCache.cs:22

Member Function Documentation

override void Deveel.Data.Caching.MemoryCache.Clear ( )
inlinevirtual

Clear the cache of all the entries.

Reimplemented from Deveel.Data.Caching.Cache.

Definition at line 116 of file MemoryCache.cs.

116  {
117  lock (syncRoot) {
118  valueCache.Clear();
119  IndexList.Clear();
120  }
121 
122  base.Clear();
123  }
readonly Dictionary< object, CacheValue > valueCache
Definition: MemoryCache.cs:24
LinkedList< KeyValuePair< object, CacheValue > > IndexList
Definition: MemoryCache.cs:22
override void Deveel.Data.Caching.MemoryCache.Dispose ( bool  disposing)
inlineprotectedvirtual

Reimplemented from Deveel.Data.Caching.Cache.

Definition at line 125 of file MemoryCache.cs.

125  {
126  if (disposing) {
127  Clear();
128  }
129 
130 
131  base.Dispose(disposing);
132  }
override void Clear()
Clear the cache of all the entries.
Definition: MemoryCache.cs:116
virtual CacheValue Deveel.Data.Caching.MemoryCache.GetCacheValueUnlocked ( object  key)
inlineprotectedvirtual

Definition at line 51 of file MemoryCache.cs.

51  {
52  CacheValue v;
53  return valueCache.TryGetValue(key, out v) ? v : null;
54  }
readonly Dictionary< object, CacheValue > valueCache
Definition: MemoryCache.cs:24
override object Deveel.Data.Caching.MemoryCache.RemoveObject ( object  key)
inlineprotectedvirtual

Implements Deveel.Data.Caching.Cache.

Definition at line 108 of file MemoryCache.cs.

108  {
109  lock (syncRoot) {
111 
112  return RemoveUnlocked(key);
113  }
114  }
object RemoveUnlocked(object key)
Definition: MemoryCache.cs:73
object Deveel.Data.Caching.MemoryCache.RemoveUnlocked ( object  key)
inlineprotected

Definition at line 73 of file MemoryCache.cs.

73  {
74  var value = GetCacheValueUnlocked(key);
75  if (value != null) {
76  valueCache.Remove(key);
77  IndexList.Remove(value.IndexRef);
78  return value.Value;
79  }
80 
81  return null;
82  }
virtual CacheValue GetCacheValueUnlocked(object key)
Definition: MemoryCache.cs:51
readonly Dictionary< object, CacheValue > valueCache
Definition: MemoryCache.cs:24
LinkedList< KeyValuePair< object, CacheValue > > IndexList
Definition: MemoryCache.cs:22
override bool Deveel.Data.Caching.MemoryCache.SetObject ( object  key,
object  value 
)
inlineprotectedvirtual

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.

Implements Deveel.Data.Caching.Cache.

Definition at line 84 of file MemoryCache.cs.

84  {
85  lock (syncRoot) {
86  var cached = SetValueUnlocked(key, value);
87  return cached.IsNew;
88  }
89  }
virtual CacheValue SetValueUnlocked(object key, object value)
Definition: MemoryCache.cs:56
virtual CacheValue Deveel.Data.Caching.MemoryCache.SetValueUnlocked ( object  key,
object  value 
)
inlineprotectedvirtual

Definition at line 56 of file MemoryCache.cs.

56  {
58  var cacheValue = GetCacheValueUnlocked(key);
59 
60  if (cacheValue == null) {
61  cacheValue = new CacheValue(value);
62  cacheValue.IsNew = true;
63  valueCache[key] = cacheValue;
64  } else {
65  cacheValue.Value = value;
66  cacheValue.IsNew = false;
67  }
68 
69  UpdateElementAccess(key, cacheValue);
70  return cacheValue;
71  }
virtual CacheValue GetCacheValueUnlocked(object key)
Definition: MemoryCache.cs:51
virtual void UpdateElementAccess(object key, CacheValue cacheValue)
Definition: MemoryCache.cs:37
readonly Dictionary< object, CacheValue > valueCache
Definition: MemoryCache.cs:24
override bool Deveel.Data.Caching.MemoryCache.TryGetObject ( object  key,
out object  value 
)
inlineprotectedvirtual

Implements Deveel.Data.Caching.Cache.

Definition at line 91 of file MemoryCache.cs.

91  {
92  CacheValue v;
93  value = null;
94 
95  lock (syncRoot) {
97  v = GetCacheValueUnlocked(key);
98  if (v != null) {
99  value = v.Value;
100  UpdateElementAccess(key, v);
101  return true;
102  }
103  }
104 
105  return false;
106  }
virtual CacheValue GetCacheValueUnlocked(object key)
Definition: MemoryCache.cs:51
virtual void UpdateElementAccess(object key, CacheValue cacheValue)
Definition: MemoryCache.cs:37
virtual void Deveel.Data.Caching.MemoryCache.UpdateElementAccess ( object  key,
CacheValue  cacheValue 
)
inlineprotectedvirtual

Reimplemented in Deveel.Data.Caching.SizeLimitedCache.

Definition at line 37 of file MemoryCache.cs.

37  {
38  // update last access and move it to the head of the list
39  cacheValue.LastAccess = DateTime.Now;
40  var idxRef = cacheValue.IndexRef;
41  if (idxRef != null) {
42  IndexList.Remove(idxRef);
43  } else {
44  idxRef = new LinkedListNode<KeyValuePair<object, CacheValue>>(new KeyValuePair<object, CacheValue>(key, cacheValue));
45  cacheValue.IndexRef = idxRef;
46  }
47 
48  IndexList.AddFirst(idxRef);
49  }
LinkedList< KeyValuePair< object, CacheValue > > IndexList
Definition: MemoryCache.cs:22

Member Data Documentation

long Deveel.Data.Caching.MemoryCache.getTotal = 0
private

Definition at line 35 of file MemoryCache.cs.

DateTime Deveel.Data.Caching.MemoryCache.lastCacheAccess = DateTime.MaxValue
private

Definition at line 27 of file MemoryCache.cs.

readonly object Deveel.Data.Caching.MemoryCache.syncRoot = new object()
private

Definition at line 26 of file MemoryCache.cs.

long Deveel.Data.Caching.MemoryCache.totalGets = 0
private

Definition at line 34 of file MemoryCache.cs.

readonly Dictionary<object, CacheValue> Deveel.Data.Caching.MemoryCache.valueCache = new Dictionary<object, CacheValue>()
private

Definition at line 24 of file MemoryCache.cs.

Property Documentation

LinkedList<KeyValuePair<object, CacheValue> > Deveel.Data.Caching.MemoryCache.IndexList
getprivate setprotected

Definition at line 22 of file MemoryCache.cs.


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