Class Cacher
java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.service.Middleware
services.moleculer.cacher.Cacher
- All Implemented Interfaces:
MetricConstants, MoleculerLifecycle
- Direct Known Subclasses:
DistributedCacher, MemoryCacher
Base superclass of all Cacher implementations.
- See Also:
-
Field Summary
FieldsFields inherited from class MoleculerComponent
broker, logger, nameFields inherited from interface MetricConstants
MOLECULER_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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendToKey(StringBuilder key, io.datatree.Tree tree) protected voidappendTree(StringBuilder key, Object source) abstract io.datatree.PromiseCleans this cache.abstract io.datatree.PromiseDeletes a content from this cache.abstract io.datatree.PromiseGets a cached content by a key.getCacheKey(String name, io.datatree.Tree params, String... keys) Creates a cacher-specific key by name and params.abstract io.datatree.PromiseLists all keys of cached entries.protected booleanIs the request disables caching?booleanisDebug()Is debug enabled?protected voidprotected voidserializeKey(StringBuilder key, io.datatree.Tree params, String... keys) abstract io.datatree.PromiseSets a content by key into the cache.voidsetDebug(boolean debug) Enable debug messages.voidstarted(ServiceBroker broker) Methods inherited from class MoleculerComponent
getBroker, getLogger, getName, stopped
-
Field Details
-
metrics
-
debug
protected boolean debug
-
-
Constructor Details
-
Cacher
public Cacher()
-
-
Method Details
-
started
- Specified by:
startedin interfaceMoleculerLifecycle- Overrides:
startedin classMoleculerComponent- Throws:
Exception
-
install
- Specified by:
installin classMiddleware
-
getCacheKey
Creates a cacher-specific key by name and params. Concatenates the name and params.- Parameters:
name- qualified name of the actionparams- input (key) structure (~JSON)keys- optional array of keys (eg. "id")- Returns:
- generated cache key
-
serializeKey
-
appendToKey
-
appendTree
-
isCachingDisabledByTheContext
Is the request disables caching?- Parameters:
ctx- Input Context- Returns:
- true, if the caching is disabled at the request level
-
logClean
-
get
Gets a cached content by a key.- Parameters:
key- cache key- Returns:
- Promise with cached value (or null, the returned Promise also can be null)
-
set
Sets a content by key into the cache.- Parameters:
key- cache keyvalue- new valuettl- optional TTL of entry (0 == use default TTL)- Returns:
- Promise with empty value
-
del
Deletes a content from this cache.- Parameters:
key- cache key- Returns:
- Promise with empty value
-
clean
Cleans this cache. Removes every key by a match string. The default match string is "**".- Parameters:
match- regex- Returns:
- Promise with empty value
-
getCacheKeys
public abstract io.datatree.Promise getCacheKeys()Lists all keys of cached entries.- Returns:
- a Tree object with a "keys" array.
-
isDebug
public boolean isDebug()Is debug enabled?- Returns:
- debug flag
-
setDebug
public void setDebug(boolean debug) Enable debug messages.- Parameters:
debug- debug mode
-