mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-04 21:01:36 +00:00
cachetools 2.1.0
This commit is contained in:
@@ -16,7 +16,7 @@ __all__ = (
|
|||||||
'cached', 'cachedmethod'
|
'cached', 'cachedmethod'
|
||||||
)
|
)
|
||||||
|
|
||||||
__version__ = '2.0.1'
|
__version__ = '2.1.0'
|
||||||
|
|
||||||
if hasattr(functools.update_wrapper(lambda f: f(), lambda: 42), '__wrapped__'):
|
if hasattr(functools.update_wrapper(lambda f: f(), lambda: 42), '__wrapped__'):
|
||||||
_update_wrapper = functools.update_wrapper
|
_update_wrapper = functools.update_wrapper
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from warnings import warn
|
||||||
|
|
||||||
from .abc import DefaultMapping
|
from .abc import DefaultMapping
|
||||||
|
|
||||||
|
|
||||||
@@ -14,16 +16,23 @@ class _DefaultSize(object):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
_deprecated = object()
|
||||||
|
|
||||||
|
|
||||||
class Cache(DefaultMapping):
|
class Cache(DefaultMapping):
|
||||||
"""Mutable mapping to serve as a simple cache or cache base class."""
|
"""Mutable mapping to serve as a simple cache or cache base class."""
|
||||||
|
|
||||||
__size = _DefaultSize()
|
__size = _DefaultSize()
|
||||||
|
|
||||||
def __init__(self, maxsize, missing=None, getsizeof=None):
|
def __init__(self, maxsize, missing=_deprecated, getsizeof=None):
|
||||||
|
if missing is not _deprecated:
|
||||||
|
warn("Cache constructor parameter 'missing' is deprecated",
|
||||||
|
DeprecationWarning, 3)
|
||||||
if missing:
|
if missing:
|
||||||
self.__missing = missing
|
self.__missing = missing
|
||||||
if getsizeof:
|
if getsizeof:
|
||||||
self.__getsizeof = getsizeof
|
self.getsizeof = getsizeof
|
||||||
|
if self.getsizeof is not Cache.getsizeof:
|
||||||
self.__size = dict()
|
self.__size = dict()
|
||||||
self.__data = dict()
|
self.__data = dict()
|
||||||
self.__currsize = 0
|
self.__currsize = 0
|
||||||
@@ -81,14 +90,6 @@ class Cache(DefaultMapping):
|
|||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.__data)
|
return len(self.__data)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def __getsizeof(value):
|
|
||||||
return 1
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def __missing(key):
|
|
||||||
raise KeyError(key)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def maxsize(self):
|
def maxsize(self):
|
||||||
"""The maximum size of the cache."""
|
"""The maximum size of the cache."""
|
||||||
@@ -99,6 +100,11 @@ class Cache(DefaultMapping):
|
|||||||
"""The current size of the cache."""
|
"""The current size of the cache."""
|
||||||
return self.__currsize
|
return self.__currsize
|
||||||
|
|
||||||
def getsizeof(self, value):
|
@staticmethod
|
||||||
|
def getsizeof(value):
|
||||||
"""Return the size of a cache element's value."""
|
"""Return the size of a cache element's value."""
|
||||||
return self.__getsizeof(value)
|
return 1
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __missing(key):
|
||||||
|
raise KeyError(key)
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from .cache import Cache
|
from .cache import Cache, _deprecated
|
||||||
|
|
||||||
|
|
||||||
class LFUCache(Cache):
|
class LFUCache(Cache):
|
||||||
"""Least Frequently Used (LFU) cache implementation."""
|
"""Least Frequently Used (LFU) cache implementation."""
|
||||||
|
|
||||||
def __init__(self, maxsize, missing=None, getsizeof=None):
|
def __init__(self, maxsize, missing=_deprecated, getsizeof=None):
|
||||||
Cache.__init__(self, maxsize, missing, getsizeof)
|
Cache.__init__(self, maxsize, missing, getsizeof)
|
||||||
self.__counter = collections.Counter()
|
self.__counter = collections.Counter()
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from .cache import Cache
|
from .cache import Cache, _deprecated
|
||||||
|
|
||||||
|
|
||||||
class LRUCache(Cache):
|
class LRUCache(Cache):
|
||||||
"""Least Recently Used (LRU) cache implementation."""
|
"""Least Recently Used (LRU) cache implementation."""
|
||||||
|
|
||||||
def __init__(self, maxsize, missing=None, getsizeof=None):
|
def __init__(self, maxsize, missing=_deprecated, getsizeof=None):
|
||||||
Cache.__init__(self, maxsize, missing, getsizeof)
|
Cache.__init__(self, maxsize, missing, getsizeof)
|
||||||
self.__order = collections.OrderedDict()
|
self.__order = collections.OrderedDict()
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,24 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from .cache import Cache
|
from .cache import Cache, _deprecated
|
||||||
|
|
||||||
|
|
||||||
|
# random.choice cannot be pickled in Python 2.7
|
||||||
|
def _choice(seq):
|
||||||
|
return random.choice(seq)
|
||||||
|
|
||||||
|
|
||||||
class RRCache(Cache):
|
class RRCache(Cache):
|
||||||
"""Random Replacement (RR) cache implementation."""
|
"""Random Replacement (RR) cache implementation."""
|
||||||
|
|
||||||
def __init__(self, maxsize, choice=random.choice, missing=None,
|
def __init__(self, maxsize, choice=random.choice, missing=_deprecated,
|
||||||
getsizeof=None):
|
getsizeof=None):
|
||||||
Cache.__init__(self, maxsize, missing, getsizeof)
|
Cache.__init__(self, maxsize, missing, getsizeof)
|
||||||
|
# TODO: use None as default, assing to self.choice directly?
|
||||||
|
if choice is random.choice:
|
||||||
|
self.__choice = _choice
|
||||||
|
else:
|
||||||
self.__choice = choice
|
self.__choice = choice
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from __future__ import absolute_import
|
|||||||
import collections
|
import collections
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from .cache import Cache
|
from .cache import Cache, _deprecated
|
||||||
|
|
||||||
|
|
||||||
class _Link(object):
|
class _Link(object):
|
||||||
@@ -57,7 +57,7 @@ class _Timer(object):
|
|||||||
class TTLCache(Cache):
|
class TTLCache(Cache):
|
||||||
"""LRU Cache implementation with per-item time-to-live (TTL) value."""
|
"""LRU Cache implementation with per-item time-to-live (TTL) value."""
|
||||||
|
|
||||||
def __init__(self, maxsize, ttl, timer=time.time, missing=None,
|
def __init__(self, maxsize, ttl, timer=time.time, missing=_deprecated,
|
||||||
getsizeof=None):
|
getsizeof=None):
|
||||||
Cache.__init__(self, maxsize, missing, getsizeof)
|
Cache.__init__(self, maxsize, missing, getsizeof)
|
||||||
self.__root = root = _Link()
|
self.__root = root = _Link()
|
||||||
|
|||||||
Reference in New Issue
Block a user