public class Cache<T> extends Object implements Disposable
The cache works by maintaining two dictionaries of entities keyed on their offset or index. The inactive list contains all items requested since the cache was created or last serviced. The active list contains all the items currently in the cache. The inactive list is always updated when an item is requested.
When the cache is serviced the active list is destroyed and the inactive list becomes the active list. i.e. all the items that were requested since the cache was last serviced are now in the cache. A new inactive list is created to store all items being requested since the cache was last serviced.
| Modifier and Type | Class and Description |
|---|---|
(package private) static interface |
Cache.EntityCreator<T> |
| Modifier and Type | Field and Description |
|---|---|
private Timer |
cacheServiceTimer |
(package private) BaseEntityFactory<T> |
entityFactory |
(package private) ConcurrentHashMap<Integer,T> |
itemsActive |
(package private) ConcurrentHashMap<Integer,T> |
itemsInactive |
(package private) AtomicInteger |
misses |
(package private) AtomicInteger |
requests |
| Constructor and Description |
|---|
Cache(BaseEntityFactory<T> creator)
Constructs a new instance of the cache.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
addRecent(int index,
T item) |
void |
dispose() |
(package private) double |
getPercentageMisses() |
ConcurrentHashMap<Integer,T> itemsActive
ConcurrentHashMap<Integer,T> itemsInactive
private final Timer cacheServiceTimer
AtomicInteger requests
AtomicInteger misses
final BaseEntityFactory<T> entityFactory
Cache(BaseEntityFactory<T> creator)
serviceCacheInternal - Time between cache servicesvoid addRecent(int index,
T item)
double getPercentageMisses()
public void dispose()
dispose in interface Disposable