mutable_cache

typhon.utils.cache.mutable_cache(maxsize=10)[source]

In-memory cache like functools.lru_cache but for any object

This is a re-implementation of functools.lru_cache. Unlike functools.lru_cache, it works for any objects, mutable or not. Therefore, it returns returns a copy and it is wrong if the mutable object has changed! Use with caution!

If you call the resulting function with a keyword argument ‘CLEAR_CACHE’, the cache will be cleared. Otherwise, cache is rotated when more than maxsize elements exist in the cache. Additionally, if you call the resulting function with NO_CACHE=True, it doesn’t cache at all. Be careful with functions returning large objects, such as reading routines for datasets like IASI. Everything is kept in RAM!

Parameters

maxsize (int) – Maximum number of return values to be remembered.

Returns

New function that has caching implemented.