pip_services3_components.cache.MemoryCache module
pip_services3_components.cache.MemoryCache
Memory cache component implementation
- copyright
Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.
- license
MIT, see LICENSE for more details.
-
class
pip_services3_components.cache.MemoryCache.
MemoryCache
Bases:
pip_services3_components.cache.ICache.ICache
,pip_services3_commons.config.IReconfigurable.IReconfigurable
,pip_services3_commons.run.ICleanable.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:
cache = MemoryCache() cache.store("123", "key1", "ABC", 0)
-
clear
(correlation_id: Optional[str]) Clears component state.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
-
configure
(config: pip_services3_commons.config.ConfigParams.ConfigParams) Configures component by passing configuration parameters.
- Parameters
config – configuration parameters to be set.
-
remove
(correlation_id: Optional[str], key: str) Removes a value from the cache by its key.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique value key.
-
retrieve
(correlation_id: Optional[str], key: str) → Any Retrieves cached value from the cache using its key. If value is missing in the cache or expired it returns None.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique value key.
- Returns
a cached value or None if value wasn’t found or timeout expired.
-
store
(correlation_id: Optional[str], key: str, value: Any, timeout: int) → Any Stores value in the cache with expiration time.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
key – a unique value key.
value – a value to store.
timeout – expiration timeout in milliseconds.
- Returns
a cached value stored in the cache.