public class MemoryCacher extends Cacher implements java.lang.Runnable
RedisCacher,
OHCacher| Modifier and Type | Class and Description |
|---|---|
protected static class |
MemoryCacher.MemoryPartition |
protected static class |
MemoryCacher.PartitionEntry |
| Modifier and Type | Field and Description |
|---|---|
protected int |
capacity
Maximum number of entries per partition
|
protected int |
cleanup
Cleanup period time, in SECONDS (0 = disable cleanup process)
|
protected MetricCounter |
counterClean |
protected MetricCounter |
counterDel |
protected MetricCounter |
counterExpired |
protected MetricCounter |
counterFound |
protected MetricCounter |
counterGet |
protected MetricCounter |
counterSet |
protected java.util.HashMap<java.lang.String,MemoryCacher.MemoryPartition> |
partitions |
protected java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock |
readLock |
protected java.util.concurrent.ScheduledFuture<?> |
timer
Cancelable timer
|
protected java.util.concurrent.atomic.AtomicBoolean |
timerStarted |
protected java.util.concurrent.atomic.AtomicBoolean |
timerStopped |
protected int |
ttl
Expire time, in SECONDS (0 = never expires)
|
protected boolean |
useCloning
Do you need to make a copy of the returned values?
|
protected java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
writeLock |
broker, logger, nameMOLECULER_CACHER_CLEAN_TIME, MOLECULER_CACHER_CLEAN_TIME_DESC, MOLECULER_CACHER_CLEAN_TOTAL, MOLECULER_CACHER_CLEAN_TOTAL_DESC, MOLECULER_CACHER_DEL_TIME, MOLECULER_CACHER_DEL_TIME_DESC, MOLECULER_CACHER_DEL_TOTAL, MOLECULER_CACHER_DEL_TOTAL_DESC, MOLECULER_CACHER_EXPIRED_TOTAL, MOLECULER_CACHER_EXPIRED_TOTAL_DESC, MOLECULER_CACHER_FOUND_TOTAL, MOLECULER_CACHER_FOUND_TOTAL_DESC, MOLECULER_CACHER_GET_TIME, MOLECULER_CACHER_GET_TIME_DESC, MOLECULER_CACHER_GET_TOTAL, MOLECULER_CACHER_GET_TOTAL_DESC, MOLECULER_CACHER_SET_TIME, MOLECULER_CACHER_SET_TIME_DESC, MOLECULER_CACHER_SET_TOTAL, MOLECULER_CACHER_SET_TOTAL_DESC, MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE, MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE_DESC, MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE, MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE_DESC, MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL, MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL_DESC, MOLECULER_EVENT_BROADCAST_TOTAL, MOLECULER_EVENT_BROADCAST_TOTAL_DESC, MOLECULER_EVENT_BROADCASTLOCAL_TOTAL, MOLECULER_EVENT_BROADCASTLOCAL_TOTAL_DESC, MOLECULER_EVENT_EMIT_TOTAL, MOLECULER_EVENT_EMIT_TOTAL_DESC, MOLECULER_EVENT_RECEIVED_ACTIVE, MOLECULER_EVENT_RECEIVED_ACTIVE_DESC, MOLECULER_EVENT_RECEIVED_ERROR_TOTAL, MOLECULER_EVENT_RECEIVED_ERROR_TOTAL_DESC, MOLECULER_EVENT_RECEIVED_TIME, MOLECULER_EVENT_RECEIVED_TIME_DESC, MOLECULER_EVENT_RECEIVED_TOTAL, MOLECULER_EVENT_RECEIVED_TOTAL_DESC, MOLECULER_EXECUTOR, MOLECULER_REQUEST_ACTIVE, MOLECULER_REQUEST_ACTIVE_DESC, MOLECULER_REQUEST_ERROR_TOTAL, MOLECULER_REQUEST_ERROR_TOTAL_DESC, MOLECULER_REQUEST_LEVELS, MOLECULER_REQUEST_LEVELS_DESC, MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL, MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL_DESC, MOLECULER_REQUEST_TIME, MOLECULER_REQUEST_TIME_DESC, MOLECULER_REQUEST_TIMEOUT_TOTAL, MOLECULER_REQUEST_TIMEOUT_TOTAL_DESC, MOLECULER_REQUEST_TOTAL, MOLECULER_REQUEST_TOTAL_DESC, MOLECULER_SCHEDULER, MOLECULER_TRANSIT_CONNECTED, MOLECULER_TRANSIT_CONNECTED_DESC, MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL, MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL_DESC, MOLECULER_TRANSIT_REQUESTS_ACTIVE, MOLECULER_TRANSIT_REQUESTS_ACTIVE_DESC, MOLECULER_TRANSIT_STREAMS_RECEIVE_ACTIVE, MOLECULER_TRANSIT_STREAMS_RECEIVE_ACTIVE_DESC, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES_DESC, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL_DESC, MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES, MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES_DESC, MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL, MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL_DESC| Constructor and Description |
|---|
MemoryCacher() |
MemoryCacher(int capacityPerPartition,
int defaultTtl) |
MemoryCacher(int capacityPerPartition,
int defaultTtl,
int cleanupSeconds) |
| Modifier and Type | Method and Description |
|---|---|
io.datatree.Promise |
clean(java.lang.String match)
Cleans this cache.
|
io.datatree.Promise |
del(java.lang.String key)
Deletes a content from this cache.
|
io.datatree.Promise |
get(java.lang.String key)
Gets a cached content by a key.
|
io.datatree.Promise |
getCacheKeys()
Lists all keys of cached entries.
|
int |
getCapacity() |
int |
getCleanup() |
protected MemoryCacher.MemoryPartition |
getPartition(java.lang.String prefix) |
int |
getTtl() |
boolean |
isUseCloning() |
protected int |
partitionPosition(java.lang.String key,
boolean throwErrorIfMissing) |
void |
run() |
io.datatree.Promise |
set(java.lang.String key,
io.datatree.Tree value,
int ttl)
Sets a content by key into the cache.
|
void |
setCapacity(int capacity) |
void |
setCleanup(int cleanup) |
void |
setTtl(int ttl) |
void |
setUseCloning(boolean useCloning) |
void |
started(ServiceBroker broker)
Initializes cacher instance.
|
protected void |
startTimer(int entryTTL) |
void |
stopped() |
appendToKey, appendTree, getCacheKey, install, isCachingDisabledByTheContext, serializeKeygetBroker, getLogger, getNameprotected int capacity
protected int ttl
protected int cleanup
protected boolean useCloning
protected final java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock readLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock writeLock
protected final java.util.HashMap<java.lang.String,MemoryCacher.MemoryPartition> partitions
protected volatile java.util.concurrent.ScheduledFuture<?> timer
protected java.util.concurrent.atomic.AtomicBoolean timerStarted
protected java.util.concurrent.atomic.AtomicBoolean timerStopped
protected MetricCounter counterExpired
protected MetricCounter counterGet
protected MetricCounter counterSet
protected MetricCounter counterDel
protected MetricCounter counterClean
protected MetricCounter counterFound
public MemoryCacher()
public MemoryCacher(int capacityPerPartition,
int defaultTtl)
public MemoryCacher(int capacityPerPartition,
int defaultTtl,
int cleanupSeconds)
public void started(ServiceBroker broker) throws java.lang.Exception
started in interface MoleculerLifecyclestarted in class Cacherbroker - parent ServiceBrokerjava.lang.Exceptionprotected void startTimer(int entryTTL)
public void run()
run in interface java.lang.Runnablepublic void stopped()
stopped in interface MoleculerLifecyclestopped in class MoleculerComponentpublic io.datatree.Promise get(java.lang.String key)
Cacherprotected MemoryCacher.MemoryPartition getPartition(java.lang.String prefix)
public io.datatree.Promise set(java.lang.String key,
io.datatree.Tree value,
int ttl)
Cacherpublic io.datatree.Promise del(java.lang.String key)
Cacherpublic io.datatree.Promise clean(java.lang.String match)
Cacherprotected int partitionPosition(java.lang.String key,
boolean throwErrorIfMissing)
public io.datatree.Promise getCacheKeys()
getCacheKeys in class Cacherpublic int getCapacity()
public void setCapacity(int capacity)
public int getTtl()
public void setTtl(int ttl)
public int getCleanup()
public void setCleanup(int cleanup)
public boolean isUseCloning()
public void setUseCloning(boolean useCloning)