How to use the cachetools.Cache.__getitem__ function in cachetools

To help you get started, we’ve selected a few cachetools 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 scrapinghub / frontera / frontera / contrib / backends / hbase / domaincache.py View on Github external
def __getitem__(self, key):
        self._key_check(key)
        try:
            value = Cache.__getitem__(self, key)
        except KeyError:
            try:
                value = self._second_gen[key]
            except KeyError:
                try:
                    value = self._get_item(key)
                except KeyError as ke3:
                    raise ke3
                else:
                    self.__setitem__(key, value)
            else:
                self.__setitem__(key, value)
                if key in self._second_gen:   # the second gen clean up could be triggered during set in first gen
                    del self._second_gen[key]
        else:
            self._update_order(key)
github frictionlessdata / datapackage-pipelines / datapackage_pipelines / utilities / kvstore.py View on Github external
def sync(self):
        for key in iter(self):
            value = cachetools.Cache.__getitem__(self, key)
            self._dbset(key, value)
github gramener / gramex / gramex / services / ttlcache.py View on Github external
    def __getitem__(self, key, cache_getitem=Cache.__getitem__):
        try:
            link = self.__getlink(key)
        except KeyError:
            expired = False
        else:
            expired = link.expire < self.__timer()
        if expired:
            return self.__missing__(key)
        else:
            return cache_getitem(self, key)
github tkem / cachetools / cachetools.py View on Github external
def popitem(self):
        """Remove and return the `(key, value)` pair least frequently used."""
        items = ((key, Cache.__getitem__(self, key)[1]) for key in self)
        try:
            key, _ = min(items, key=operator.itemgetter(1))
        except ValueError:
            raise KeyError('cache is empty')
        return (key, self.pop(key))
github tkem / cachetools / cachetools.py View on Github external
    def __repr__(self, cache_getitem=Cache.__getitem__):
        return '%s(%r, maxsize=%d, currsize=%d)' % (
            self.__class__.__name__,
            [(key, cache_getitem(self, key)[0]) for key in self],
            self.maxsize,
            self.currsize,
        )
github scrapinghub / frontera / frontera / contrib / backends / hbase / domaincache.py View on Github external
    def __getitem__(self, key, cache_getitem=Cache.__getitem__):
        value = cache_getitem(self, key)
        self._update_order(key)
        return value