Skip to content

olirice/cachetools_ext

Repository files navigation

cachetools_ext

Tests

Python version PyPI version License Download count


Source Code: https://github.com/olirice/cachetools_ext


An extension for cachetools

Installation:

pip install cachetools_ext

Features:

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

Usage:

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()

About

cachetools extension adding backends

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages