public class ChainCache extends Object implements Cache
During fetch, caches are tested in order. In backtrack mode (the default), when a hit occurs, the entry is stored in all previous caches before the hit, so that subsequent fetches would find the entry in the faster caches. Other operations always work on all caches indiscriminately.
Constructor and Description |
---|
ChainCache()
Constructor.
|
ChainCache(Cache... caches)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
CacheEntry |
fetch(String key)
Fetches an entry from the cache if it's there and has not yet expired.
|
boolean |
getBacktrack() |
CopyOnWriteArrayList<Cache> |
getCaches()
The chained caches.
|
void |
invalidate(String tag)
Makes sure that all tagged entries are un-fetchable.
|
boolean |
isBacktrack()
When true (the default), makes sure to store a cache hit in previous
caches along the chain.
|
void |
prune()
Removes expired cache entries.
|
void |
reset()
Removes all entries in the cache.
|
void |
setBacktrack(boolean backtrack) |
void |
store(String key,
CacheEntry entry)
Stores an entry in the cache.
|
public ChainCache()
public ChainCache(Cache... caches)
caches
- The initial cachespublic CopyOnWriteArrayList<Cache> getCaches()
public boolean isBacktrack()
public boolean getBacktrack()
isBacktrack()
public void setBacktrack(boolean backtrack)
backtrack
- The backtrack modeisBacktrack()
public void store(String key, CacheEntry entry)
Cache
CacheEntry.getExpirationDate()
, although it may very well
be un-fetchable sooner.
Keys are unique to the cache. Storing for a key that already exists will replace the entry if it exists.
public CacheEntry fetch(String key)
Cache
public void invalidate(String tag)
Cache
invalidate
in interface Cache
tag
- The cache tagpublic void prune()
Cache
Copyright © 2009-2016 Three Crickets LLC.