public class DefaultServerCache extends Object implements ServerCache
It is base on ConcurrentHashMap with periodic trimming using a TimerTask. The periodic trimming means that an LRU list does not have to be maintained.
Modifier and Type | Class and Description |
---|---|
static class |
DefaultServerCache.CacheEntry
Wraps the values to additionally hold createTime and lastAccessTime.
|
Constructor and Description |
---|
DefaultServerCache(String name,
int maxSize,
int maxIdleSecs,
int maxSecsToLive) |
DefaultServerCache(String name,
ServerCacheOptions options) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the cache.
|
Object |
get(Object key)
Return a value from the cache.
|
int |
getHitRatio()
Return the hit ratio the cache is currently getting.
|
long |
getMaxIdleSecs()
Return the max idle time.
|
long |
getMaxSecsToLive()
Return the maximum time to live.
|
int |
getMaxSize()
Return the max cache size.
|
String |
getName()
Return the name of the cache.
|
ServerCacheOptions |
getOptions()
Return the configuration options for this cache.
|
ServerCacheStatistics |
getStatistics(boolean reset)
Return statistics for the cache.
|
void |
init(EbeanServer server)
Just after a cache is created this init method is called.
|
Object |
put(Object key,
Object value)
Put a value into the cache.
|
Object |
putIfAbsent(Object key,
Object value)
Put a value into the cache but only if absent.
|
Object |
remove(Object key)
Remove an entry from the cache.
|
void |
setMaxIdleSecs(int maxIdleSecs)
Set the max idle time.
|
void |
setMaxSecsToLive(int maxSecsToLive)
Set the maximum time to live.
|
void |
setMaxSize(int maxSize)
Set the max cache size.
|
void |
setOptions(ServerCacheOptions o)
Update the configuration options for this cache.
|
int |
size()
Return the number of elements in the cache.
|
public DefaultServerCache(String name, ServerCacheOptions options)
public DefaultServerCache(String name, int maxSize, int maxIdleSecs, int maxSecsToLive)
public void init(EbeanServer server)
ServerCache
This method is called after the cache is constructed but before the cache is made available for use.
init
in interface ServerCache
public ServerCacheStatistics getStatistics(boolean reset)
ServerCache
getStatistics
in interface ServerCache
reset
- if true the statistics are reset.public int getHitRatio()
ServerCache
getHitRatio
in interface ServerCache
public ServerCacheOptions getOptions()
ServerCache
getOptions
in interface ServerCache
public void setOptions(ServerCacheOptions o)
ServerCache
setOptions
in interface ServerCache
public int getMaxSize()
public void setMaxSize(int maxSize)
public long getMaxIdleSecs()
public void setMaxIdleSecs(int maxIdleSecs)
public long getMaxSecsToLive()
public void setMaxSecsToLive(int maxSecsToLive)
public String getName()
public void clear()
clear
in interface ServerCache
public Object get(Object key)
get
in interface ServerCache
public Object put(Object key, Object value)
put
in interface ServerCache
public Object putIfAbsent(Object key, Object value)
putIfAbsent
in interface ServerCache
public Object remove(Object key)
remove
in interface ServerCache
public int size()
size
in interface ServerCache
Copyright © 2015. All Rights Reserved.