Prepare v0.7.0
diff --git a/CHANGES.rst b/CHANGES.rst
index b4a2b4a..1084110 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,4 +1,4 @@
-0.7.0 UNRELEASED
+0.7.0 2014-11-12
----------------
- Deprecate ``TTLCache.ExpiredError``.
@@ -7,7 +7,7 @@
- Refactor ``LFUCache``, ``LRUCache`` and ``TTLCache``.
-- Always use custom ``NullContext`` implementation for unsynchronized
+- Use custom ``NullContext`` implementation for unsynchronized
function decorators.
diff --git a/README.rst b/README.rst
index c14e124..770c20d 100644
--- a/README.rst
+++ b/README.rst
@@ -2,8 +2,8 @@
========================================================================
This module provides various memoizing collections and decorators,
-including a variant of the Python 3 Standard Library
-``functools.lru_cache`` function decorator.
+including a variant of the Python 3 Standard Library `@lru_cache`_
+function decorator.
.. code-block:: pycon
@@ -76,7 +76,7 @@
Licensed under the `MIT License`_.
-.. _functools.lru_cache: http://docs.python.org/3.4/library/functools.html#functools.lru_cache
+.. _@lru_cache: http://docs.python.org/3/library/functools.html#functools.lru_cache
.. _mutable: http://docs.python.org/dev/glossary.html#term-mutable
.. _mapping: http://docs.python.org/dev/glossary.html#term-mapping
.. _cache algorithm: http://en.wikipedia.org/wiki/Cache_algorithms
diff --git a/docs/index.rst b/docs/index.rst
index 02455f9..2428956 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -4,8 +4,8 @@
.. module:: cachetools
This module provides various memoizing collections and decorators,
-including a variant of the Python 3 Standard Library
-:func:`functools.lru_cache` function decorator.
+including a variant of the Python 3 Standard Library `@lru_cache`_
+function decorator.
.. code-block:: pycon
@@ -57,10 +57,10 @@
.. autoclass:: Cache
:members:
-.. autoclass:: LRUCache
+.. autoclass:: LFUCache
:members:
-.. autoclass:: LFUCache
+.. autoclass:: LRUCache
:members:
.. autoclass:: RRCache
@@ -77,11 +77,11 @@
from cachetools import TTLCache
import time
- cache = TTLCache(maxsize=100, ttl=1)
+ cache = TTLCache(maxsize=100, ttl=1.0)
cache.update({1: 1, 2: 2, 3: 3})
- time.sleep(1)
for key in cache:
+ time.sleep(0.5)
try:
print(cache[key])
except KeyError:
@@ -93,11 +93,27 @@
This module provides several memoizing function decorators compatible
with -- though not necessarily as efficient as -- the Python 3
-Standard Library :func:`functools.lru_cache` decorator.
+Standard Library :func:`functools.lru_cache` decorator::
-In addition to a `maxsize` parameter, all decorators feature optional
-arguments, which should be specified as keyword arguments for
-compatibility with future extensions:
+ import cachetools
+ import urllib.request
+
+ @cachetools.lru_cache(maxsize=32)
+ def get_pep(num):
+ """Retrieve text of a Python Enhancement Proposal"""
+ url = 'http://www.python.org/dev/peps/pep-%04d/' % num
+ with urllib.request.urlopen(url) as s:
+ return s.read()
+
+ for n in 8, 290, 308, 320, 8, 218, 320, 279, 289, 320, 9991:
+ try:
+ print(n, len(get_pep(n)))
+ except urllib.error.HTTPError:
+ print(n, 'Not Found')
+ print(get_pep.cache_info())
+
+In addition to a `maxsize` parameter, all decorators feature some
+optional keyword arguments:
- `typed`, if is set to :const:`True`, will cause function arguments
of different types to be cached separately.
@@ -120,12 +136,6 @@
Unlike :func:`functools.lru_cache`, setting `maxsize` to zero or
:const:`None` is not supported.
-.. decorator:: rr_cache(maxsize=128, choice=random.choice, typed=False, getsizeof=None, lock=threading.RLock)
-
- Decorator that wraps a function with a memoizing callable that
- saves up to `maxsize` results based on a Random Replacement (RR)
- algorithm.
-
.. decorator:: lfu_cache(maxsize=128, typed=False, getsizeof=None, lock=threading.RLock)
Decorator that wraps a function with a memoizing callable that
@@ -138,6 +148,12 @@
saves up to `maxsize` results based on a Least Recently Used (LRU)
algorithm.
+.. decorator:: rr_cache(maxsize=128, choice=random.choice, typed=False, getsizeof=None, lock=threading.RLock)
+
+ Decorator that wraps a function with a memoizing callable that
+ saves up to `maxsize` results based on a Random Replacement (RR)
+ algorithm.
+
.. decorator:: ttl_cache(maxsize=128, ttl=600, timer=time.time, typed=False, getsizeof=None, lock=threading.RLock)
Decorator to wrap a function with a memoizing callable that saves
@@ -172,20 +188,21 @@
class CachedPEPs(object):
- def __init__(self, cachesize):
- self.cache = LRUCache(maxsize=cachesize)
+ def __init__(self, cachesize):
+ self.cache = LRUCache(maxsize=cachesize)
- @cachedmethod(operator.attrgetter('cache'))
- def get(self, num):
- """Retrieve text of a Python Enhancement Proposal"""
- url = 'http://www.python.org/dev/peps/pep-%04d/' % num
- with urllib.request.urlopen(url) as s:
- return s.read()
+ @cachedmethod(operator.attrgetter('cache'))
+ def get(self, num):
+ """Retrieve text of a Python Enhancement Proposal"""
+ url = 'http://www.python.org/dev/peps/pep-%04d/' % num
+ with urllib.request.urlopen(url) as s:
+ return s.read()
peps = CachedPEPs(cachesize=10)
print("PEP #1: %s" % peps.get(1))
+.. _@lru_cache: http://docs.python.org/3/library/functools.html#functools.lru_cache
.. _mutable: http://docs.python.org/dev/glossary.html#term-mutable
.. _mapping: http://docs.python.org/dev/glossary.html#term-mapping
.. _cache algorithm: http://en.wikipedia.org/wiki/Cache_algorithms