Class MemoryCache
java.lang.Object
org.pipservices3.components.cache.MemoryCache
- All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable,org.pipservices3.commons.config.IReconfigurable,org.pipservices3.commons.run.ICleanable,ICache
public class MemoryCache extends Object implements ICache, org.pipservices3.commons.config.IReconfigurable, org.pipservices3.commons.run.ICleanable
Cache that stores values in the process memory.
Remember: 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)
### Example ###
MemoryCache cache = new MemoryCache();
cache.store("123", "key1", "ABC", 0);
- See Also:
ICache
-
Constructor Summary
Constructors Constructor Description MemoryCache()Creates instance of local in-memory cache component -
Method Summary
Modifier and Type Method Description voidclear(String correlationId)Clears component state.voidconfigure(org.pipservices3.commons.config.ConfigParams config)Configures component by passing configuration parameters.voidremove(String correlationId, String key)Removes a value from the cache by its key.Objectretrieve(String correlationId, String key)Retrieves cached value from the cache using its key.Objectstore(String correlationId, String key, Object value, long timeout)Stores value in the cache with expiration time.
-
Constructor Details
-
MemoryCache
public MemoryCache()Creates instance of local in-memory cache component
-
-
Method Details
-
configure
public void configure(org.pipservices3.commons.config.ConfigParams config) throws org.pipservices3.commons.errors.ConfigExceptionConfigures component by passing configuration parameters.- Specified by:
configurein interfaceorg.pipservices3.commons.config.IConfigurable- Parameters:
config- configuration parameters to be set.- Throws:
org.pipservices3.commons.errors.ConfigException- when component is in illegal state or configuration validation fails.
-
retrieve
Retrieves cached value from the cache using its key. If value is missing in the cache or expired it returns null. -
store
Stores value in the cache with expiration time. -
remove
Removes a value from the cache by its key. -
clear
Clears component state.- Specified by:
clearin interfaceorg.pipservices3.commons.run.ICleanable- Parameters:
correlationId- (optional) transaction id to trace execution through call chain.
-