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 void
clear(String correlationId)
Clears component state.void
configure(org.pipservices3.commons.config.ConfigParams config)
Configures component by passing configuration parameters.void
remove(String correlationId, String key)
Removes a value from the cache by its key.Object
retrieve(String correlationId, String key)
Retrieves cached value from the cache using its key.Object
store(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:
configure
in 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:
clear
in interfaceorg.pipservices3.commons.run.ICleanable
- Parameters:
correlationId
- (optional) transaction id to trace execution through call chain.
-