21 namespace Deveel.Data.Caching {
26 public const int DefaultHashSize = 88547;
28 public const int DefaultMaxSize = 1024*1024;
30 public const int DefaultMaxSize = 512*512;
33 public const int DefaultMaxCellSize = 1024*64;
36 Configure(configuration);
43 public int MaxCellSize {
get;
private set; }
55 GC.SuppressFinalize(
this);
72 var hashSize = DefaultHashSize;
73 var maxSize = config.GetInt32(
"system.tableCellCache.maxSize", DefaultMaxSize);
74 MaxCellSize = config.GetInt32(
"system.tableCellCache.maxCellSize", DefaultMaxCellSize);
77 cache =
new Cache(
this, baseCache, hashSize, maxSize);
81 var value = cell.
Value;
83 if (!value.IsCacheable)
87 int memoryUse = AmountMemory(value);
88 if (memoryUse <= MaxCellSize) {
95 if (!Equals(removedCell, null)) {
96 size -= AmountMemory(removedCell);
100 cache.
Set(key, value);
110 private void Remove(
string database,
int tableId,
long rowNumber,
int columnOffset) {
112 var cell = cache.
Remove(
new CacheKey(database, tableId, (
int)rowNumber, (
short)columnOffset));
125 var tableKey = key.
RowId.TableId;
126 var row = key.
RowId.RowNumber;
130 if (!cache.
TryGet(
new CacheKey(database, tableKey, row, (
short)columnIndex), out obj)) {
166 this.tableCache = tableCache;
167 this.hashSize = hashSize;
176 if (tableCache.Size >= hashSize) {
186 return (tableCache.Size >= (
int)((hashSize * 100L) / 115L));
190 base.OnWipingNode(ob);
194 tableCache.ReduceCacheSize(AmountMemory(value));
197 protected override void OnGetWalks(
long totalWalks,
long totalGetOps) {
199 base.OnGetWalks(totalWalks, totalGetOps);
213 public CacheKey(
string database,
int tableId,
int row,
short column) {
214 this.database = database;
215 this.tableId = tableId;
217 this.column = column;
220 public override bool Equals(
object obj) {
226 return (database.GetHashCode() + (((int)column + tableId + (row * 189977)) * 50021) << 4);
230 return database.Equals(other.
database) &&
override void OnGetWalks(long totalWalks, long totalGetOps)
Notifies that some statistical information about the hash map has updated.
override void Clear()
Clear the cache of all the entries.
void ReduceCacheSize(long value)
bool TryGetValue(CellKey key, out DataObject value)
void Set(CachedCell cell)
virtual int NodeCount
Gets the number of nodes that are currently being stored in the cache.
void Remove(string database, int tableId, long rowNumber, int columnOffset)
override bool Equals(object obj)
bool TryGet(object key, out object value)
Tries to get an object for the given key from the underlying cache system.
TableCellCache(IConfiguration configuration)
override void OnWipingNode(object ob)
Notifies that the given object has been wiped from the cache by the clean up procedure.
CacheKey(string database, int tableId, int row, short column)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
readonly TableCellCache tableCache
Defines the contract for the configuration node of a component within the system or of the system its...
void Configure(IConfiguration config)
bool Set(object key, object value)
Puts an object into the cache with the given key.
Cache(TableCellCache tableCache, ICache baseCache, int hashSize, int maxSize)
bool Equals(CacheKey other)
Provides a contract to access a caching system.
override int GetHashCode()
override void CheckClean()
This is called whenever at object is put into the cache.
override bool WipeMoreNodes()
Checks if the clean-up method should clean up more elements from the cache.
object Remove(Object key)
Removes a node for the given key from the cache.
void ChangeSize(int newSize)
void Dispose(bool disposing)
static int AmountMemory(DataObject value)