METADATA 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. Metadata-Version: 2.1
  2. Name: cachetools
  3. Version: 3.1.1
  4. Summary: Extensible memoizing collections and decorators
  5. Home-page: https://github.com/tkem/cachetools
  6. Author: Thomas Kemmer
  7. Author-email: tkemmer@computer.org
  8. License: MIT
  9. Keywords: cache caching memoize memoizing memoization LRU LFU TTL
  10. Platform: UNKNOWN
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: Environment :: Other Environment
  13. Classifier: Intended Audience :: Developers
  14. Classifier: License :: OSI Approved :: MIT License
  15. Classifier: Operating System :: OS Independent
  16. Classifier: Programming Language :: Python
  17. Classifier: Programming Language :: Python :: 2
  18. Classifier: Programming Language :: Python :: 2.7
  19. Classifier: Programming Language :: Python :: 3
  20. Classifier: Programming Language :: Python :: 3.4
  21. Classifier: Programming Language :: Python :: 3.5
  22. Classifier: Programming Language :: Python :: 3.6
  23. Classifier: Programming Language :: Python :: 3.7
  24. Classifier: Programming Language :: Python :: Implementation :: CPython
  25. Classifier: Programming Language :: Python :: Implementation :: PyPy
  26. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  27. cachetools
  28. ========================================================================
  29. This module provides various memoizing collections and decorators,
  30. including variants of the Python 3 Standard Library `@lru_cache`_
  31. function decorator.
  32. .. code-block:: python
  33. from cachetools import cached, LRUCache, TTLCache
  34. # speed up calculating Fibonacci numbers with dynamic programming
  35. @cached(cache={})
  36. def fib(n):
  37. return n if n < 2 else fib(n - 1) + fib(n - 2)
  38. # cache least recently used Python Enhancement Proposals
  39. @cached(cache=LRUCache(maxsize=32))
  40. def get_pep(num):
  41. url = 'http://www.python.org/dev/peps/pep-%04d/' % num
  42. with urllib.request.urlopen(url) as s:
  43. return s.read()
  44. # cache weather data for no longer than ten minutes
  45. @cached(cache=TTLCache(maxsize=1024, ttl=600))
  46. def get_weather(place):
  47. return owm.weather_at_place(place).get_weather()
  48. For the purpose of this module, a *cache* is a mutable_ mapping_ of a
  49. fixed maximum size. When the cache is full, i.e. by adding another
  50. item the cache would exceed its maximum size, the cache must choose
  51. which item(s) to discard based on a suitable `cache algorithm`_. In
  52. general, a cache's size is the total size of its items, and an item's
  53. size is a property or function of its value, e.g. the result of
  54. ``sys.getsizeof(value)``. For the trivial but common case that each
  55. item counts as ``1``, a cache's size is equal to the number of its
  56. items, or ``len(cache)``.
  57. Multiple cache classes based on different caching algorithms are
  58. implemented, and decorators for easily memoizing function and method
  59. calls are provided, too.
  60. For more information, please refer to the online documentation_.
  61. Installation
  62. ------------------------------------------------------------------------
  63. Install cachetools using pip::
  64. pip install cachetools
  65. Project Resources
  66. ------------------------------------------------------------------------
  67. .. image:: http://img.shields.io/pypi/v/cachetools.svg?style=flat
  68. :target: https://pypi.python.org/pypi/cachetools/
  69. :alt: Latest PyPI version
  70. .. image:: http://img.shields.io/travis/tkem/cachetools/master.svg?style=flat
  71. :target: https://travis-ci.org/tkem/cachetools/
  72. :alt: Travis CI build status
  73. .. image:: http://img.shields.io/coveralls/tkem/cachetools/master.svg?style=flat
  74. :target: https://coveralls.io/r/tkem/cachetools
  75. :alt: Test coverage
  76. .. image:: https://readthedocs.org/projects/cachetools/badge/?version=latest&style=flat
  77. :target: http://cachetools.readthedocs.io/en/latest/
  78. :alt: Documentation Status
  79. - `Issue Tracker`_
  80. - `Source Code`_
  81. - `Change Log`_
  82. License
  83. ------------------------------------------------------------------------
  84. Copyright (c) 2014-2019 Thomas Kemmer.
  85. Licensed under the `MIT License`_.
  86. .. _@lru_cache: http://docs.python.org/3/library/functools.html#functools.lru_cache
  87. .. _mutable: http://docs.python.org/dev/glossary.html#term-mutable
  88. .. _mapping: http://docs.python.org/dev/glossary.html#term-mapping
  89. .. _cache algorithm: http://en.wikipedia.org/wiki/Cache_algorithms
  90. .. _Documentation: http://cachetools.readthedocs.io/en/latest/
  91. .. _Issue Tracker: https://github.com/tkem/cachetools/issues/
  92. .. _Source Code: https://github.com/tkem/cachetools/
  93. .. _Change Log: https://github.com/tkem/cachetools/blob/master/CHANGES.rst
  94. .. _MIT License: http://raw.github.com/tkem/cachetools/master/LICENSE