How to use the ipinfo.cache.interface.CacheInterface function in ipinfo

To help you get started, we’ve selected a few ipinfo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipinfo / python / ipinfo / cache / default.py View on Github external
"""
A default cache implementation that uses `cachetools` for an in-memory LRU cache.
"""

import cachetools

from .interface import CacheInterface


class DefaultCache(CacheInterface):
    """Default, in-memory cache."""

    def __init__(self, **cache_options):
        self.cache = cachetools.TTLCache(**cache_options)

    def __contains__(self, key):
        return self.cache.__contains__(key)

    def __setitem__(self, key, value):
        return self.cache.__setitem__(key, value)

    def __getitem__(self, key):
        return self.cache.__getitem__(key)