|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.deltava.util.cache.Cache<T>
public abstract class Cache<T extends Cacheable>
An an abstract class to store common cache operations. These caches can store null entries to prevent repeated uncached calls for invalid keys.
| Field Summary | |
|---|---|
protected ConcurrentMap<Object,CacheEntry<T>> |
_cache
|
| Constructor Summary | |
|---|---|
protected |
Cache(int maxSize)
Initializes the cache. |
| Method Summary | |
|---|---|
void |
add(T entry)
Adds an entry to the cache. |
void |
addAll(Collection<? extends T> entries)
Adds a number of entries to the cache. |
protected abstract void |
addEntry(T entry)
Adds an entry to the cache. |
void |
addNull(String key)
Adds a null entry to the cache. |
protected abstract void |
addNullEntry(Object key)
Adds a null entry to the cache. |
protected void |
checkOverflow()
Automatically resizes the cache in the case of an overflow. |
void |
clear()
Clears the cache. |
boolean |
contains(Object key)
Returns if the cache contains a particular cache key. |
abstract T |
get(Object key)
Retrieves an entry from the cache. |
long |
getHits()
Returns the total number of cache hits. |
int |
getMaxSize()
Returns the maximum size of the cache. |
long |
getRequests()
Returns the total number of cache requests |
protected void |
hit()
Log a cache hit. |
void |
remove(Object key)
Invalidate a cache entry. |
protected void |
request()
Log a cache request. |
void |
setMaxSize(int size)
Sets the maximum size of the cache. |
int |
size()
Returns the current size of the cache. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected ConcurrentMap<Object,CacheEntry<T extends Cacheable>> _cache
| Constructor Detail |
|---|
protected Cache(int maxSize)
maxSize - the maximum size of the cache| Method Detail |
|---|
public void addAll(Collection<? extends T> entries)
entries - a Collection of Cacheable entriespublic boolean contains(Object key)
key - the cache key
public void clear()
public void remove(Object key)
key - the entry keypublic final int size()
public final int getMaxSize()
public final void setMaxSize(int size)
size - the maximum number of entriesprotected void checkOverflow()
protected void hit()
get(Object) method to keep
statistics.
request(),
getHits(),
getRequests()protected void request()
get(Object) method to keep
statistics.
hit(),
getRequests()public final long getHits()
getRequests()public final long getRequests()
getHits()protected abstract void addEntry(T entry)
entry - the entry to addprotected abstract void addNullEntry(Object key)
key - the entry keypublic final void add(T entry)
entry - the entry to addpublic final void addNull(String key)
key - the entry keypublic abstract T get(Object key)
key - the cache key
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||