Cache that stores values in the process memory.
Implements: ICache, IReconfigurable
Description
The MemoryCache class allows you to create a cache that stores values in the process memory.
Important points
- This implementation is not suitable for synchronization of distributed processes.
Configuration parameters
options:
- timeout: default caching timeout in milliseconds (default: 1 minute)
- max_size: maximum number of values stored in this cache (default: 1000)
Instance methods
configure
Configures component by passing configuration parameters.
publicvoid configure(ConfigParams config) throws ConfigException
- config: ConfigParams - configuration parameters to be set.
remove
Removes a value from the cache by its key.
publicvoid remove(IContext context, String key)
- context: IContext - (optional) a context to trace execution through call chain.
- key: String - a unique value key.
retrieve
Retrieves cached value from the cache using its key. If value is missing in the cache or expired it returns null.
publicObject retrieve(IContext context, String key)
- context: IContext - (optional) a context to trace execution through call chain.
- key: String - a unique value key.
- returns: Object - a cached value or null if value wasn’t found or timeout expired.
store
Stores value in the cache with expiration time.
publicObject store(IContext context, String key, Object value, long timeout)
- context: IContext - (optional) a context to trace execution through call chain.
- key: String - a unique value key.
- value: Object - a value to store.
- timeout: long - expiration timeout in milliseconds.
- returns: Object - a cached value stored in the cache.
Examples
{@code
MemoryCache cache = new MemoryCache();
cache.store("123", "key1", "ABC", 0);
}