net.eduvax.util
public class Cache<K,V> extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Cache.LFU<K>
Trivial LFU implementation.
|
static class |
Cache.LRU<K>
Default and trivial LRU implementation.
|
static class |
Cache.Rand<K>
Trivial Random cache strategy.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Hashtable<K,V> |
_cachedObjs
Cached objects
|
private int |
_cSize
cache current size
|
private DataSource<K,V> |
_dataSource
data source
|
private int |
_maxSize
cache max size
|
private CacheStrategy<K> |
_strategy
Cache management sstrategy.
|
Constructor and Description |
---|
Cache(int size,
DataSource<K,V> data)
Create new cache usign defaults LRU strategy.
|
Cache(int size,
DataSource<K,V> data,
CacheStrategy<K> cs)
Create new cache.
|
private CacheStrategy<K> _strategy
private int _cSize
private int _maxSize
private DataSource<K,V> _dataSource
public Cache(int size, DataSource<K,V> data)
size
- cache size (max object count in cache).data
- data sourcepublic Cache(int size, DataSource<K,V> data, CacheStrategy<K> cs)
size
- cache size (max object count in cache).data
- data sourcestrategy
- Cache mangement strategy.public V get(K key)
private void insert(K key, V obj)
private void init(int size, DataSource<K,V> data, CacheStrategy<K> cs)
size
- cache size (max object count in cache).data
- data sourcestrategy
- Cache mangement strategy.