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

Classes

class  Cache
 
class  CacheKey
 

Public Member Functions

 TableCellCache (IConfiguration configuration)
 
void Dispose ()
 
void Set (CachedCell cell)
 
bool TryGetValue (CellKey key, out DataObject value)
 
void Remove (CellKey key)
 
void Clear ()
 
 TableCellCache (IDatabaseContext context, ICache baseCase, int maxSize, int maxCellSize)
 
 TableCellCache (IDatabaseContext context, ICache baseCase, int maxSize, int maxCellSize, int hashSize)
 
void Clear ()
 
void AlterCacheDynamics (int maxCacheSize, int maxCellSize)
 
void Set (int tableKey, int row, int column, DataObject value)
 
DataObject Get (int tableKey, int row, int column)
 
DataObject Remove (int tableKey, int row, int column)
 

Public Attributes

const int DefaultHashSize = 88547
 
const int DefaultMaxSize = 512*512
 
const int DefaultMaxCellSize = 1024*64
 

Properties

int MaxCellSize [get, private set]
 
long Size [get]
 
IDatabaseContext Context [get, private set]
 

Private Member Functions

 ~TableCellCache ()
 
void Dispose (bool disposing)
 
void ReduceCacheSize (long value)
 
void Configure (IConfiguration config)
 
void Remove (string database, int tableId, long rowNumber, int columnOffset)
 
void ReduceCacheSize (long value)
 

Static Private Member Functions

static int AmountMemory (DataObject value)
 
static int AmountMemory (DataObject value)
 

Private Attributes

Cache cache
 
long size
 

Detailed Description

Definition at line 22 of file TableCellCache.cs.

Constructor & Destructor Documentation

Deveel.Data.Caching.TableCellCache.TableCellCache ( IConfiguration  configuration)
inline

Definition at line 35 of file TableCellCache.cs.

35  {
36  Configure(configuration);
37  }
void Configure(IConfiguration config)
Deveel.Data.Caching.TableCellCache.~TableCellCache ( )
inlineprivate

Definition at line 39 of file TableCellCache.cs.

39  {
40  Dispose(false);
41  }
Deveel.Data.Caching.TableCellCache.TableCellCache ( IDatabaseContext  context,
ICache  baseCase,
int  maxSize,
int  maxCellSize 
)
inline

Definition at line 28 of file TableCellCache.old.cs.

29  : this(context, baseCase, maxSize, maxCellSize, DefaultHashSize) {
30  }
Deveel.Data.Caching.TableCellCache.TableCellCache ( IDatabaseContext  context,
ICache  baseCase,
int  maxSize,
int  maxCellSize,
int  hashSize 
)
inline

Definition at line 32 of file TableCellCache.old.cs.

32  {
33  Context = context;
34  MaxCellSize = maxCellSize;
35 
36  cache = new Cache(this, baseCase, hashSize, maxSize);
37  }

Member Function Documentation

void Deveel.Data.Caching.TableCellCache.AlterCacheDynamics ( int  maxCacheSize,
int  maxCellSize 
)
inline

Definition at line 69 of file TableCellCache.old.cs.

69  {
70  lock (this) {
71  MaxCellSize = maxCellSize;
72  cache.ChangeSize(maxCacheSize);
73  }
74  }
static int Deveel.Data.Caching.TableCellCache.AmountMemory ( DataObject  value)
inlinestaticprivate

Definition at line 104 of file TableCellCache.old.cs.

104  {
105  return 16 + value.CacheUsage;
106  }
static int Deveel.Data.Caching.TableCellCache.AmountMemory ( DataObject  value)
inlinestaticprivate

Definition at line 118 of file TableCellCache.cs.

118  {
119  return 16 + value.CacheUsage;
120  }
void Deveel.Data.Caching.TableCellCache.Clear ( )
inline

Implements Deveel.Data.Caching.ITableCellCache.

Definition at line 55 of file TableCellCache.old.cs.

55  {
56  lock (this) {
57  if (cache.NodeCount == 0 && Size != 0) {
58  // TODO: Raise an error
59  }
60  if (cache.NodeCount != 0) {
61  cache.Clear();
62  // TODO: Register the statistics
63  }
64 
65  size = 0;
66  }
67  }
override void Clear()
Clear the cache of all the entries.
Definition: CacheAdapter.cs:39
virtual int NodeCount
Gets the number of nodes that are currently being stored in the cache.
Definition: Cache.cs:125
void Deveel.Data.Caching.TableCellCache.Clear ( )
inline

Implements Deveel.Data.Caching.ITableCellCache.

Definition at line 144 of file TableCellCache.cs.

144  {
145  lock (this) {
146  if (cache.NodeCount == 0 && Size != 0) {
147  // TODO: Raise an error
148  }
149  if (cache.NodeCount != 0) {
150  cache.Clear();
151  // TODO: Register the statistics
152  }
153 
154  size = 0;
155  }
156  }
override void Clear()
Clear the cache of all the entries.
Definition: CacheAdapter.cs:39
virtual int NodeCount
Gets the number of nodes that are currently being stored in the cache.
Definition: Cache.cs:125
void Deveel.Data.Caching.TableCellCache.Configure ( IConfiguration  config)
inlineprivate

Definition at line 71 of file TableCellCache.cs.

71  {
72  var hashSize = DefaultHashSize;
73  var maxSize = config.GetInt32("system.tableCellCache.maxSize", DefaultMaxSize);
74  MaxCellSize = config.GetInt32("system.tableCellCache.maxCellSize", DefaultMaxCellSize);
75 
76  var baseCache = new SizeLimitedCache(maxSize);
77  cache = new Cache(this, baseCache, hashSize, maxSize);
78  }
void Deveel.Data.Caching.TableCellCache.Dispose ( )
inline

Definition at line 53 of file TableCellCache.cs.

53  {
54  Dispose(true);
55  GC.SuppressFinalize(this);
56  }
void Deveel.Data.Caching.TableCellCache.Dispose ( bool  disposing)
inlineprivate

Definition at line 58 of file TableCellCache.cs.

58  {
59  if (disposing) {
60  if (cache != null)
61  cache.Dispose();
62  }
63 
64  cache = null;
65  }
DataObject Deveel.Data.Caching.TableCellCache.Get ( int  tableKey,
int  row,
int  column 
)
inline

Definition at line 108 of file TableCellCache.old.cs.

108  {
109  lock (this) {
110  return (DataObject)cache.Get(new CacheKey(tableKey, row, (short)column));
111  }
112  }
void Deveel.Data.Caching.TableCellCache.ReduceCacheSize ( long  value)
inlineprivate

Definition at line 51 of file TableCellCache.old.cs.

51  {
52  size -= value;
53  }
void Deveel.Data.Caching.TableCellCache.ReduceCacheSize ( long  value)
inlineprivate

Definition at line 67 of file TableCellCache.cs.

67  {
68  size -= value;
69  }
void Deveel.Data.Caching.TableCellCache.Remove ( string  database,
int  tableId,
long  rowNumber,
int  columnOffset 
)
inlineprivate

Definition at line 110 of file TableCellCache.cs.

110  {
111  lock (this) {
112  var cell = cache.Remove(new CacheKey(database, tableId, (int)rowNumber, (short)columnOffset));
113  if (cell != null)
114  size -= AmountMemory((DataObject) cell);
115  }
116  }
object Remove(Object key)
Removes a node for the given key from the cache.
Definition: Cache.cs:178
static int AmountMemory(DataObject value)
DataObject Deveel.Data.Caching.TableCellCache.Remove ( int  tableKey,
int  row,
int  column 
)
inline

Definition at line 114 of file TableCellCache.old.cs.

114  {
115  lock (this) {
116  var cell = (DataObject)cache.Remove(new CacheKey(tableKey, row, (short)column));
117  if (cell != null)
118  size -= AmountMemory(cell);
119 
120  return cell;
121  }
122  }
object Remove(Object key)
Removes a node for the given key from the cache.
Definition: Cache.cs:178
static int AmountMemory(DataObject value)
void Deveel.Data.Caching.TableCellCache.Remove ( CellKey  key)
inline

Implements Deveel.Data.Caching.ITableCellCache.

Definition at line 140 of file TableCellCache.cs.

140  {
141  Remove(key.Database, key.RowId.TableId, key.RowId.RowNumber, key.ColumnOffset);
142  }
void Remove(string database, int tableId, long rowNumber, int columnOffset)
void Deveel.Data.Caching.TableCellCache.Set ( int  tableKey,
int  row,
int  column,
DataObject  value 
)
inline

Definition at line 76 of file TableCellCache.old.cs.

76  {
77  if (!value.IsCacheable)
78  throw new ArgumentException(String.Format("A value of type '{0}' cannot be stored in cache.", value.Type));
79 
80  lock (this) {
81  int memoryUse = AmountMemory(value);
82  if (memoryUse <= MaxCellSize) {
83  // Generate the key
84  var key = new CacheKey(tableKey, row, (short)column);
85 
86  // If there is an existing object here, remove it from the cache and
87  // update the current_cache_size.
88  var removedCell = (DataObject) cache.Remove(key);
89  if (!Equals(removedCell, null)) {
90  size -= AmountMemory(removedCell);
91  }
92 
93  // Put the new entry in the cache
94  cache.Set(key, value);
95  size += memoryUse;
96  } else {
97  // If the object is larger than the minimum object size that can be
98  // cached, remove any existing entry (possibly smaller) from the cache.
99  Remove(tableKey, row, column);
100  }
101  }
102  }
A long string in the system.
void Remove(string database, int tableId, long rowNumber, int columnOffset)
bool Set(object key, object value)
Puts an object into the cache with the given key.
Definition: Cache.cs:150
object Remove(Object key)
Removes a node for the given key from the cache.
Definition: Cache.cs:178
static int AmountMemory(DataObject value)
void Deveel.Data.Caching.TableCellCache.Set ( CachedCell  cell)
inline

Implements Deveel.Data.Caching.ITableCellCache.

Definition at line 80 of file TableCellCache.cs.

80  {
81  var value = cell.Value;
82 
83  if (!value.IsCacheable)
84  return;
85 
86  lock (this) {
87  int memoryUse = AmountMemory(value);
88  if (memoryUse <= MaxCellSize) {
89  // Generate the key
90  var key = new CacheKey(cell.Database, cell.TableId, (int)cell.RowNumber, (short)cell.ColumnOffset);
91 
92  // If there is an existing object here, remove it from the cache and
93  // update the current_cache_size.
94  var removedCell = (DataObject)cache.Remove(key);
95  if (!Equals(removedCell, null)) {
96  size -= AmountMemory(removedCell);
97  }
98 
99  // Put the new entry in the cache
100  cache.Set(key, value);
101  size += memoryUse;
102  } else {
103  // If the object is larger than the minimum object size that can be
104  // cached, remove any existing entry (possibly smaller) from the cache.
105  Remove(cell.Database, cell.TableId, cell.RowNumber, cell.ColumnOffset);
106  }
107  }
108  }
void Remove(string database, int tableId, long rowNumber, int columnOffset)
bool Set(object key, object value)
Puts an object into the cache with the given key.
Definition: Cache.cs:150
object Remove(Object key)
Removes a node for the given key from the cache.
Definition: Cache.cs:178
static int AmountMemory(DataObject value)
bool Deveel.Data.Caching.TableCellCache.TryGetValue ( CellKey  key,
out DataObject  value 
)
inline

Implements Deveel.Data.Caching.ITableCellCache.

Definition at line 122 of file TableCellCache.cs.

122  {
123  lock (this) {
124  var database = key.Database;
125  var tableKey = key.RowId.TableId;
126  var row = key.RowId.RowNumber;
127  var columnIndex = key.ColumnOffset;
128 
129  object obj;
130  if (!cache.TryGet(new CacheKey(database, tableKey, row, (short)columnIndex), out obj)) {
131  value = null;
132  return false;
133  }
134 
135  value = (DataObject) obj;
136  return true;
137  }
138  }
bool TryGet(object key, out object value)
Tries to get an object for the given key from the underlying cache system.
Definition: Cache.cs:162

Member Data Documentation

Cache Deveel.Data.Caching.TableCellCache.cache
private

Definition at line 23 of file TableCellCache.cs.

const int Deveel.Data.Caching.TableCellCache.DefaultHashSize = 88547

Definition at line 26 of file TableCellCache.cs.

const int Deveel.Data.Caching.TableCellCache.DefaultMaxCellSize = 1024*64

Definition at line 33 of file TableCellCache.cs.

const int Deveel.Data.Caching.TableCellCache.DefaultMaxSize = 512*512

Definition at line 30 of file TableCellCache.cs.

long Deveel.Data.Caching.TableCellCache.size
private

Definition at line 24 of file TableCellCache.cs.

Property Documentation

IDatabaseContext Deveel.Data.Caching.TableCellCache.Context
getprivate set

Definition at line 49 of file TableCellCache.old.cs.

int Deveel.Data.Caching.TableCellCache.MaxCellSize
getprivate set

Definition at line 43 of file TableCellCache.cs.

long Deveel.Data.Caching.TableCellCache.Size
get

Definition at line 45 of file TableCellCache.cs.


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