Thomas Kemmer | fa0e606 | 2014-03-22 11:09:33 +0100 | [diff] [blame] | 1 | cachetools |
| 2 | ======================================================================== |
| 3 | |
Thomas Kemmer | bf206e0 | 2014-05-06 20:26:34 +0200 | [diff] [blame] | 4 | This module provides various memoizing collections and decorators, |
| 5 | including a variant of the Python 3 Standard Library |
Thomas Kemmer | 8e1d7ed | 2014-06-16 20:46:19 +0200 | [diff] [blame] | 6 | ``functools.lru_cache`` function decorator. |
Thomas Kemmer | fa0e606 | 2014-03-22 11:09:33 +0100 | [diff] [blame] | 7 | |
| 8 | .. code-block:: pycon |
| 9 | |
Thomas Kemmer | 35f85f2 | 2014-03-25 06:44:31 +0100 | [diff] [blame] | 10 | >>> from cachetools import LRUCache |
| 11 | >>> cache = LRUCache(maxsize=2) |
Thomas Kemmer | b210c14 | 2014-06-16 20:22:12 +0200 | [diff] [blame] | 12 | >>> cache.update([('first', 1), ('second', 2)]) |
Thomas Kemmer | 35f85f2 | 2014-03-25 06:44:31 +0100 | [diff] [blame] | 13 | >>> cache |
Thomas Kemmer | b210c14 | 2014-06-16 20:22:12 +0200 | [diff] [blame] | 14 | LRUCache([('second', 2), ('first', 1)], maxsize=2, currsize=2) |
Thomas Kemmer | 35f85f2 | 2014-03-25 06:44:31 +0100 | [diff] [blame] | 15 | >>> cache['third'] = 3 |
| 16 | >>> cache |
Thomas Kemmer | b210c14 | 2014-06-16 20:22:12 +0200 | [diff] [blame] | 17 | LRUCache([('second', 2), ('third', 3)], maxsize=2, currsize=2) |
Thomas Kemmer | 35f85f2 | 2014-03-25 06:44:31 +0100 | [diff] [blame] | 18 | >>> cache['second'] |
| 19 | 2 |
Thomas Kemmer | 35f85f2 | 2014-03-25 06:44:31 +0100 | [diff] [blame] | 20 | >>> cache['fourth'] = 4 |
Thomas Kemmer | b210c14 | 2014-06-16 20:22:12 +0200 | [diff] [blame] | 21 | LRUCache([('second', 2), ('fourth', 4)], maxsize=2, currsize=2) |
Thomas Kemmer | 35f85f2 | 2014-03-25 06:44:31 +0100 | [diff] [blame] | 22 | |
Thomas Kemmer | bf206e0 | 2014-05-06 20:26:34 +0200 | [diff] [blame] | 23 | |
Thomas Kemmer | b210c14 | 2014-06-16 20:22:12 +0200 | [diff] [blame] | 24 | For the purpose of this module, a *cache* is a mutable_ mapping_ of a |
Thomas Kemmer | a837142 | 2014-09-25 18:06:23 +0200 | [diff] [blame] | 25 | fixed maximum size. When the cache is full, i.e. the size of the |
| 26 | cache would exceed its maximum size, the cache must choose which |
| 27 | item(s) to discard based on a suitable `cache algorithm`_. A cache's |
| 28 | size is the sum of the size of its items, and an item's size in |
| 29 | general is a property or function of its value, e.g. the result of |
| 30 | ``sys.getsizeof``, or ``len`` for string and sequence values. |
Thomas Kemmer | 35f85f2 | 2014-03-25 06:44:31 +0100 | [diff] [blame] | 31 | |
Thomas Kemmer | 101513c | 2014-11-05 19:56:17 +0100 | [diff] [blame^] | 32 | This module provides multiple cache implementations based on different |
Thomas Kemmer | 35f85f2 | 2014-03-25 06:44:31 +0100 | [diff] [blame] | 33 | cache algorithms, as well as decorators for easily memoizing function |
Thomas Kemmer | bf206e0 | 2014-05-06 20:26:34 +0200 | [diff] [blame] | 34 | and method calls. |
Thomas Kemmer | fa0e606 | 2014-03-22 11:09:33 +0100 | [diff] [blame] | 35 | |
| 36 | |
| 37 | Installation |
| 38 | ------------------------------------------------------------------------ |
| 39 | |
| 40 | Install cachetools using pip:: |
| 41 | |
| 42 | pip install cachetools |
| 43 | |
| 44 | |
| 45 | Project Resources |
| 46 | ------------------------------------------------------------------------ |
| 47 | |
Thomas Kemmer | 2f95610 | 2014-10-12 15:03:51 +0200 | [diff] [blame] | 48 | .. image:: http://img.shields.io/pypi/v/cachetools.svg?style=flat |
Thomas Kemmer | 4649656 | 2014-10-23 18:44:58 +0200 | [diff] [blame] | 49 | :target: https://pypi.python.org/pypi/cachetools/ |
| 50 | :alt: Latest PyPI version |
Thomas Kemmer | bf206e0 | 2014-05-06 20:26:34 +0200 | [diff] [blame] | 51 | |
Thomas Kemmer | 2f95610 | 2014-10-12 15:03:51 +0200 | [diff] [blame] | 52 | .. image:: http://img.shields.io/pypi/dm/cachetools.svg?style=flat |
Thomas Kemmer | 4649656 | 2014-10-23 18:44:58 +0200 | [diff] [blame] | 53 | :target: https://pypi.python.org/pypi/cachetools/ |
| 54 | :alt: Number of PyPI downloads |
Thomas Kemmer | bf206e0 | 2014-05-06 20:26:34 +0200 | [diff] [blame] | 55 | |
Thomas Kemmer | c22a043 | 2014-11-04 20:04:22 +0100 | [diff] [blame] | 56 | .. image:: http://img.shields.io/travis/tkem/cachetools/master.svg?style=flat |
Thomas Kemmer | 4649656 | 2014-10-23 18:44:58 +0200 | [diff] [blame] | 57 | :target: https://travis-ci.org/tkem/cachetools/ |
| 58 | :alt: Travis CI build status |
| 59 | |
Thomas Kemmer | c22a043 | 2014-11-04 20:04:22 +0100 | [diff] [blame] | 60 | .. image:: http://img.shields.io/coveralls/tkem/cachetools/master.svg?style=flat |
Thomas Kemmer | 4649656 | 2014-10-23 18:44:58 +0200 | [diff] [blame] | 61 | :target: https://coveralls.io/r/tkem/cachetools |
| 62 | :alt: Test coverage |
Thomas Kemmer | 2f95610 | 2014-10-12 15:03:51 +0200 | [diff] [blame] | 63 | |
Thomas Kemmer | a34b1fa | 2014-03-22 12:57:39 +0100 | [diff] [blame] | 64 | - `Documentation`_ |
| 65 | - `Issue Tracker`_ |
| 66 | - `Source Code`_ |
| 67 | - `Change Log`_ |
Thomas Kemmer | fa0e606 | 2014-03-22 11:09:33 +0100 | [diff] [blame] | 68 | |
Thomas Kemmer | a34b1fa | 2014-03-22 12:57:39 +0100 | [diff] [blame] | 69 | |
| 70 | License |
| 71 | ------------------------------------------------------------------------ |
| 72 | |
Thomas Kemmer | 573b318 | 2014-04-02 20:44:06 +0200 | [diff] [blame] | 73 | Copyright (c) 2014 Thomas Kemmer. |
Thomas Kemmer | a34b1fa | 2014-03-22 12:57:39 +0100 | [diff] [blame] | 74 | |
| 75 | Licensed under the `MIT License`_. |
| 76 | |
| 77 | |
Thomas Kemmer | 35f85f2 | 2014-03-25 06:44:31 +0100 | [diff] [blame] | 78 | .. _functools.lru_cache: http://docs.python.org/3.4/library/functools.html#functools.lru_cache |
Thomas Kemmer | bf206e0 | 2014-05-06 20:26:34 +0200 | [diff] [blame] | 79 | .. _mutable: http://docs.python.org/dev/glossary.html#term-mutable |
Thomas Kemmer | 35f85f2 | 2014-03-25 06:44:31 +0100 | [diff] [blame] | 80 | .. _mapping: http://docs.python.org/dev/glossary.html#term-mapping |
| 81 | .. _cache algorithm: http://en.wikipedia.org/wiki/Cache_algorithms |
Thomas Kemmer | a34b1fa | 2014-03-22 12:57:39 +0100 | [diff] [blame] | 82 | |
| 83 | .. _Documentation: http://pythonhosted.org/cachetools/ |
Thomas Kemmer | a34b1fa | 2014-03-22 12:57:39 +0100 | [diff] [blame] | 84 | .. _Issue Tracker: https://github.com/tkem/cachetools/issues/ |
Thomas Kemmer | 78408a1 | 2014-09-18 05:32:16 +0200 | [diff] [blame] | 85 | .. _Source Code: https://github.com/tkem/cachetools/ |
Thomas Kemmer | 101513c | 2014-11-05 19:56:17 +0100 | [diff] [blame^] | 86 | .. _Change Log: https://github.com/tkem/cachetools/blob/master/CHANGES.rst |
Thomas Kemmer | 3b9d819 | 2014-03-27 06:23:04 +0100 | [diff] [blame] | 87 | .. _MIT License: http://raw.github.com/tkem/cachetools/master/LICENSE |