21 namespace Deveel.Data.Caching {
22 public sealed
class TableCellCache {
26 public const int DefaultHashSize = 88547;
29 : this(context, baseCase, maxSize, maxCellSize, DefaultHashSize) {
34 MaxCellSize = maxCellSize;
36 cache =
new Cache(
this, baseCase, hashSize, maxSize);
47 public int MaxCellSize {
get;
private set; }
57 if (cache.NodeCount == 0 && Size != 0) {
60 if (cache.NodeCount != 0) {
71 MaxCellSize = maxCellSize;
72 cache.ChangeSize(maxCacheSize);
78 throw new ArgumentException(String.Format(
"A value of type '{0}' cannot be stored in cache.", value.
Type));
81 int memoryUse = AmountMemory(value);
82 if (memoryUse <= MaxCellSize) {
84 var key =
new CacheKey(tableKey, row, (
short)column);
88 var removedCell = (
DataObject) cache.Remove(key);
89 if (!Equals(removedCell, null)) {
90 size -= AmountMemory(removedCell);
94 cache.Set(key, value);
99 Remove(tableKey, row, column);
118 size -= AmountMemory(cell);
128 private int hashSize;
131 : base(baseCache, maxSize) {
132 this.tableCache = tableCache;
133 this.hashSize = hashSize;
142 if (tableCache.Size >= hashSize) {
152 return (tableCache.Size >= (
int)((hashSize * 100L) / 115L));
156 base.OnWipingNode(ob);
160 tableCache.ReduceCacheSize(AmountMemory(value));
163 protected override void OnGetWalks(
long totalWalks,
long totalGetOps) {
165 base.OnGetWalks(totalWalks, totalGetOps);
173 class CacheKey : IEquatable<CacheKey> {
174 private readonly
short column;
175 private readonly
int row;
176 private readonly
int tableId;
178 public CacheKey(
int tableId,
int row,
short column) {
179 this.tableId = tableId;
181 this.column = column;
184 public override bool Equals(
object obj) {
190 return (((
int)column + tableId + (row * 189977)) * 50021) << 4;
194 return row == other.row &&
195 column == other.column &&
196 tableId == other.tableId;
SqlType Type
Gets the SqlType that defines the object properties
override void OnGetWalks(long totalWalks, long totalGetOps)
Notifies that some statistical information about the hash map has updated.
The context of a single database within a system.
void ReduceCacheSize(long value)
override bool Equals(object obj)
override void OnWipingNode(object ob)
Notifies that the given object has been wiped from the cache by the clean up procedure.
TableCellCache(IDatabaseContext context, ICache baseCase, int maxSize, int maxCellSize, int hashSize)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
void AlterCacheDynamics(int maxCacheSize, int maxCellSize)
TableCellCache(IDatabaseContext context, ICache baseCase, int maxSize, int maxCellSize)
Cache(TableCellCache tableCache, ICache baseCache, int hashSize, int maxSize)
bool Equals(CacheKey other)
Represents a cache of Objects. /summary>
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.
CacheKey(int tableId, int row, short column)
override bool WipeMoreNodes()
Checks if the clean-up method should clean up more elements from the cache.
DataObject Remove(int tableKey, int row, int column)
void ChangeSize(int newSize)
void Set(int tableKey, int row, int column, DataObject value)
static int AmountMemory(DataObject value)
DataObject Get(int tableKey, int row, int column)