Class RongCache
-
- All Implemented Interfaces:
public class RongCache<K, V>
Modify by DragonJ on 14/11/28. Add queue for change the way of recycle.
-
-
Constructor Summary
Constructors Constructor Description RongCache(int maxSize)
-
Method Summary
Modifier and Type Method Description void
resize(int maxSize)
Sets the size of the cache. final V
get(K key)
Returns the value for key
if it exists in the cache or can be created by#create
.final V
put(K key, V value)
Caches value
forkey
.final V
remove(K key)
Removes the entry for key
if it exists.void
clear()
final void
evictAll()
Clear the cache, calling entryRemoved on each removed entry. final synchronized int
size()
For caches that do not override sizeOf, this returns the number of entries in the cache. final synchronized int
maxSize()
For caches that do not override sizeOf, this returns the maximum number of entries in the cache. final synchronized int
hitCount()
Returns the number of times get returned a value that was already present in the cache. final synchronized int
missCount()
Returns the number of times get returned null or required a new value to be created. final synchronized int
createCount()
Returns the number of times create returned a value. final synchronized int
putCount()
Returns the number of times put was called. final synchronized int
evictionCount()
Returns the number of values that have been evicted. final synchronized Map<K, V>
snapshot()
Returns a copy of the current contents of the cache, ordered from least recently accessed to most recently accessed. final synchronized String
toString()
-
-
Method Detail
-
resize
void resize(int maxSize)
Sets the size of the cache.
- Parameters:
maxSize
- The new maximum size.
-
get
final V get(K key)
Returns the value for
key
if it exists in the cache or can be created by#create
. If a value was returned, it is moved to the head of the queue. This returns null if a value is not cached and cannot be created.
-
put
final V put(K key, V value)
Caches
value
forkey
. The value is moved to the head of the queue.- Returns:
the previous value mapped by
key
.
-
remove
final V remove(K key)
Removes the entry for
key
if it exists.- Returns:
the previous value mapped by
key
.
-
clear
void clear()
-
evictAll
final void evictAll()
Clear the cache, calling entryRemoved on each removed entry.
-
size
final synchronized int size()
For caches that do not override sizeOf, this returns the number of entries in the cache. For all other caches, this returns the sum of the sizes of the entries in this cache.
-
maxSize
final synchronized int maxSize()
For caches that do not override sizeOf, this returns the maximum number of entries in the cache. For all other caches, this returns the maximum sum of the sizes of the entries in this cache.
-
hitCount
final synchronized int hitCount()
Returns the number of times get returned a value that was already present in the cache.
-
missCount
final synchronized int missCount()
Returns the number of times get returned null or required a new value to be created.
-
createCount
final synchronized int createCount()
Returns the number of times create returned a value.
-
evictionCount
final synchronized int evictionCount()
Returns the number of values that have been evicted.
-
snapshot
final synchronized Map<K, V> snapshot()
Returns a copy of the current contents of the cache, ordered from least recently accessed to most recently accessed.
-
toString
final synchronized String toString()
-
-
-
-