Package com.mckoi.database
Class DataCellCache
- java.lang.Object
-
- com.mckoi.database.DataCellCache
-
final class DataCellCache extends java.lang.Object
This object represents a cache for accesses to the the data cells within a Table. Whenever a column/row index to a cell is accessed, the cache is first checked. If the cell is not in the cache then it may go ahead and read the cell from the file.ISSUE: We may need to keep track of memory used. Since a String may use up much memory, we may need a cap on the maximum size the cache can grow to. For example, we wouldn't want to cache a large document. This could be handled at a higher level?
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
DataCellCache.DCCache
This extends the 'Cache' class.private static class
DataCellCache.DCCacheKey
Inner class that creates an object that hashes nicely over the cache source.
-
Field Summary
Fields Modifier and Type Field Description private DataCellCache.DCCache
cache
The master cache.private long
current_cache_size
The current size of the cache.private int
MAX_CELL_SIZE
The maximum size of a DataCell that is allowed to go in the cache.private static int[]
PRIME_LIST
A list of primes ordered from lowest to highest.private TransactionSystem
system
The TransactionSystem that this cache is from.
-
Constructor Summary
Constructors Constructor Description DataCellCache(TransactionSystem system, int max_cache_size, int max_cell_size)
DataCellCache(TransactionSystem system, int max_cache_size, int max_cell_size, int hash_size)
The Constructors.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
alterCacheDynamics(int max_cache_size, int max_cell_size)
Dynamically resizes the data cell cache so it can store more/less data.private static int
amountMemory(TObject cell)
Returns an approximation of the amount of memory taken by a TObject.(package private) static int
closestPrime(int value)
Returns a prime number from PRIME_LIST that is the closest prime greater or equal to the given value.TObject
get(int table_key, int row, int column)
Gets a TObject from the cache.long
getCurrentCacheSize()
Returns an estimation of the current cache size in bytes.void
put(int table_key, int row, int column, TObject cell)
Puts a TObject on the cache for the given row/column of the table.private void
reduceCacheSize(long val)
Reduce the cache size by the given amount.TObject
remove(int table_key, int row, int column)
Removes a TObject from the cache.void
wipe()
Completely wipe the cache of all entries.
-
-
-
Field Detail
-
system
private final TransactionSystem system
The TransactionSystem that this cache is from.
-
MAX_CELL_SIZE
private int MAX_CELL_SIZE
The maximum size of a DataCell that is allowed to go in the cache.
-
cache
private final DataCellCache.DCCache cache
The master cache.
-
current_cache_size
private long current_cache_size
The current size of the cache.
-
PRIME_LIST
private static final int[] PRIME_LIST
A list of primes ordered from lowest to highest.
-
-
Constructor Detail
-
DataCellCache
DataCellCache(TransactionSystem system, int max_cache_size, int max_cell_size, int hash_size)
The Constructors.- Parameters:
max_cache_size
- the maximum size in bytes that the cache is allowed to grow to (eg. 4000000).max_cell_size
- the maximum size of an object that can be stored in the cache.hash_size
- the number of elements in the hash (should be a prime number).
-
DataCellCache
DataCellCache(TransactionSystem system, int max_cache_size, int max_cell_size)
-
-
Method Detail
-
alterCacheDynamics
public void alterCacheDynamics(int max_cache_size, int max_cell_size)
Dynamically resizes the data cell cache so it can store more/less data. This is used to change cache dynamics at runtime.
-
amountMemory
private static final int amountMemory(TObject cell)
Returns an approximation of the amount of memory taken by a TObject.
-
put
public void put(int table_key, int row, int column, TObject cell)
Puts a TObject on the cache for the given row/column of the table. Ignores any cells that are larger than the maximum size.
-
get
public TObject get(int table_key, int row, int column)
Gets a TObject from the cache. If the row/column is not in the cache then it returns null.
-
remove
public TObject remove(int table_key, int row, int column)
Removes a TObject from the cache. This is used when we need to notify the cache that an object has become outdated. This should be used when the cell has been removed or changed. Returns the cell that was removed, or null if there was no cell at the given location.
-
wipe
public void wipe()
Completely wipe the cache of all entries.
-
getCurrentCacheSize
public long getCurrentCacheSize()
Returns an estimation of the current cache size in bytes.
-
reduceCacheSize
private void reduceCacheSize(long val)
Reduce the cache size by the given amount.
-
closestPrime
static int closestPrime(int value)
Returns a prime number from PRIME_LIST that is the closest prime greater or equal to the given value.
-
-