aboutsummaryrefslogtreecommitdiff
path: root/README.rst
diff options
context:
space:
mode:
authorThomas Kemmer <tkemmer@computer.org>2014-06-16 20:22:12 +0200
committerThomas Kemmer <tkemmer@computer.org>2014-06-16 20:26:49 +0200
commitb210c14c7fb336205625be8d29ece52c2fba6abe (patch)
treef88d56ebd5cf4849aa1df15a4445e1611d0f5e89 /README.rst
parent059216bd26fd6ae308fe1b378c1c3f4aa114d052 (diff)
downloadcachetools-b210c14c7fb336205625be8d29ece52c2fba6abe.tar.gz
Prepare v0.4.0
Diffstat (limited to 'README.rst')
-rw-r--r--README.rst39
1 files changed, 16 insertions, 23 deletions
diff --git a/README.rst b/README.rst
index 4b01431..af046ed 100644
--- a/README.rst
+++ b/README.rst
@@ -9,35 +9,28 @@ including a variant of the Python 3 Standard Library
>>> from cachetools import LRUCache
>>> cache = LRUCache(maxsize=2)
- >>> cache['first'] = 1
- >>> cache['second'] = 2
+ >>> cache.update([('first', 1), ('second', 2)])
>>> cache
- LRUCache(OrderedDict([('first', 1), ('second', 2)]), size=2, maxsize=2)
+ LRUCache([('second', 2), ('first', 1)], maxsize=2, currsize=2)
>>> cache['third'] = 3
>>> cache
- LRUCache(OrderedDict([('second', 2), ('third', 3)]), size=2, maxsize=2)
+ LRUCache([('second', 2), ('third', 3)], maxsize=2, currsize=2)
>>> cache['second']
2
- >>> cache
- LRUCache(OrderedDict([('third', 3), ('second', 2)]), size=2, maxsize=2)
>>> cache['fourth'] = 4
- >>> cache
- LRUCache(OrderedDict([('second', 2), ('fourth', 4)]), size=2, maxsize=2)
-
-For the purpose of this module, a *cache* is a mutable_ mapping_ with
-additional attributes ``size`` and ``maxsize``, which hold the current
-and maximum size of the cache, and a (possibly static) method
-``getsizeof``.
-
-The current size of the cache is the sum of the results of
-``getsizeof`` applied to each of the cache's values, i.e. ``cache.size
-== sum(map(cache.getsizeof, cache.values()), 0)``. As a special case,
-if ``getsizeof`` returns ``1`` irrespective of its argument,
-``cache.size == len(cache)``.
-
-When the cache is full, i.e. ``cache.size > cache.maxsize``, the cache
-must choose which item(s) to discard based on a suitable `cache
-algorithm`_.
+ LRUCache([('second', 2), ('fourth', 4)], maxsize=2, currsize=2)
+
+
+For the purpose of this module, a *cache* is a mutable_ mapping_ of a
+fixed maximum *size*. When the cache is full, i.e. the current size
+of the cache exceeds its maximum size, the cache must choose which
+item(s) to discard based on a suitable `cache algorithm`_.
+
+In general, a cache's size is the sum of the size of its items. If
+the size of each items is :const:`1`, a cache's size is equal to the
+number of its items, i.e. :func:`len`. An items's size may also be a
+property or function of its value, e.g. the result of
+:func:`sys.getsizeof`, or :func:`len` for string and sequence values.
This module provides various cache implementations based on different
cache algorithms, as well as decorators for easily memoizing function