Example #1
0
 def __init__(self,
              default_ttl=None,
              expire_interval=60,
              touch_on_access=False,
              max_items=None,
              recent_items=RECENT_SIZE):
     """
        @param default_ttl: time to live when using __setitem__ rather than set.
        @param expire_interval:  time between removals of expired items in seconds. Otherwise,
            expired items are removed lazily.
        @param touch_on_access: refresh item expire time by ttl when item is accessed.
        @param max_items: maximum size of cache.  (see replacement algorithm above)
     """
     self._exp = IndexedMultiMap(
     )  # expiration times.  Multiple items can have the same expiration
     # times, but there can only be one instance of any one key
     # in the CacheMap.
     self._data = {}
     self._ttl = default_ttl
     self._touch = touch_on_access
     self._max_items = max_items
     self._expire_interval = expire_interval
     if max_items is not None:
         self._recent = _BoundedCacheSet(int(min(recent_items, max_items)))
     else:
         self._recent = None
     reactor.callLater(self._expire_interval, self._expire)
Example #2
0
 def __init__(self, max_items):
     assert max_items > 1
     self._max_items = max_items
     self._data = IndexedMultiMap()  # recent accesses.