Cache
Custom caches and utilities
- class LRUCache(func: Callable, maxsize: int = 8)[source]
Bases:
object
Custom Least Recently Used (LRU) memory cache.
- Parameters:
func (class or func) -- Function result or class instantiation to be cached.
maxsize (int, optional) -- Maximum size of the cache.
Bases:
object
Custom, dictionary-based, Least Recently Used (LRU) reader-writer lockable cache, shareable across processes.
- Parameters:
func (Callable) -- Function to be cached.
name (str, optional) -- Name of the lock cache.
maxsize (int, optional) -- Maximum size of the cache.
shared (bool, optional) -- Share dictionary across processes (requires POSIX IPC support)
removecall (func, optional) -- Callback function for removing cached data.
logger (logging.Logger, optional) -- Logger object to display cache handling information.
Get or recover a cached entry, not shared with other processes.
- Parameters:
args (any) -- Hashable arguments to the cache dictionary.
kwargs (any) -- Hashable keyworded arguments to the cache dictionary.
- Returns:
result -- Cached output.
lock -- Reader-Writer lock associated with args, set to None.
msg -- "OK" or error string in case of an exception.
:meta public:
Get or recover a cached entry, not shared with other processes.
- Parameters:
args (any) -- Hashable arguments to the cache dictionary.
kwargs (any) -- Hashable keyworded arguments to the cache dictionary.
- Returns:
result -- Cached output.
lock -- Reader-Writer lock associated with args.
msg -- "OK" or error string in case of an exception.
:meta public:
Remove semaphores.
Bases:
object
Custom reader-writer lock shareable across processes
See Raynal, Michel (2012), Concurrent Programming: Algorithms, Principles, and Foundations, Springer.
- Parameters:
name (str, optional) -- Name of the lock.
Acquire lock in read mode.
Acquire lock in write mode.
Release acquired read lock.
Release acquired write lock.
Remove files used by the RW lock semaphores and shared memory.