Source Code: https://github.com/olirice/cachetools_ext
An extension for cachetools
pip install cachetools_ext
cachetools_ext.fs.FSLRUCache:
- A
cachetools.cached
compatible file system backed LRU cache with optional TTL. Note, the cache key must be a string. - Parameters:
maxsize: int = maximum number of entries in the cache before evicting
path: Optional[Union[str, pathlib.Path]] = path to the sqlite database (does not need to exist)
ttl: Optional[int] = time to live in seconds
clear_on_start: bool = if true, clear the cache on instantiation
from pathlib import Path
from urllib import request
from cachetools import cached
from cachetools_ext.fs import FSLRUCache
@cached(cache=FSLRUCache(maxsize=32, ttl=360), key=lambda x: f'get_pep|num={x}')
def get_pep(num):
"""Lookup a Python Enhacement Proposals (PEP) by id"""
url = 'http://www.python.org/dev/peps/pep-%04d/' % num
with request.urlopen(url) as s:
return s.read()