Example #1
0
 def __init__(self, cache, *args, **kwargs):
     if isinstance(cache, Number):
         cache = cachey.Cache(cache, *args, **kwargs)
     else:
         assert not args and not kwargs
     self.cache = cache
     self.starttimes = dict()
Example #2
0
 def __init__(self, cache, *args, **kwargs):
     try:
         import cachey
     except ImportError as ex:
         raise ImportError('Cache requires cachey, "{ex}" problem '
                           "importing".format(ex=str(ex))) from ex
     self._nbytes = cachey.nbytes
     if isinstance(cache, Number):
         cache = cachey.Cache(cache, *args, **kwargs)
     else:
         assert not args and not kwargs
     self.cache = cache
     self.starttimes = dict()
Example #3
0
    def __init__(self, available_bytes_in_process):
        self.misses = 0
        self.hits = 0

        def miss(key):
            self.misses += 1
            if __debug__:
                logger.debug("Miss %r", key)

        def hit(key, value):
            self.hits += 1
            if __debug__:
                logger.debug("Hit %r", key)

        self._cache = cachey.Cache(available_bytes_in_process,
                                   0,
                                   miss=miss,
                                   hit=hit)
        self._dask_context = DaskCache(self)
Example #4
0
    def cache(self) -> cachey.Cache:
        """Returns the :class:`cachey.Cache` instance used by the FastAPI application."""

        if self._cache is None:
            self._cache = cachey.Cache(**self._cache_kws)
        return self._cache