{ "info": { "author": "bofm", "author_email": "bofm@github.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "Status\n======\n\nWORK IN PROGRESS\n----------------\n\nCaching\n=======\n\n|Build Status| |Coverage Status| |Python Versions|\n\nPython utils and decorators for c\u0430ching with TTL, maxsize and file-based storage.\n\nInstallation\n============\n\n``pip install caching``\n\nUsage\n=====\n\n.. code:: python\n\n from caching import Cache\n\n # File-based cache with unlimited ttl and maximum of 128 cached results\n @Cache(ttl=-1, maxsize=128, filepath='/tmp/mycache')\n def long_running_function(a, b, *args, c=None, **kwargs):\n pass\n\n # Memory-based cache with limited ttl and maxsize and \"least recently used\"\n # cache replacement policy.\n @Cache(ttl=60, maxsize=128, policy='LRU')\n def long_running_function(a, b, *args, c=None, **kwargs):\n pass\n\nAdvanced usage\n==============\n\n.. code:: python\n\n from caching import Cache\n\n # One cache for many functions\n\n cache = Cache(filepath='/tmp/mycache', ttl=3600, maxsize=1024)\n\n @cache\n def pow(x, y):\n return x**y\n\n @cache\n def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n-1)\n\n\n # Caching the last result and returning it only in case of errors\n\n @Cache(maxsize=1, only_on_errors=(ConnectionError, TimeoutError))\n def api_request():\n \"\"\"Request some remote resource which sometimes become unavailable.\n If this functions raises ConnectionError or TimeoutError, then the\n last cached result will be returned, if available.\"\"\"\n\n\n # Custom cache key function\n \n @Cache(key=lambda x: x[0])\n def toupper(a):\n global call_count\n call_count += 1\n return str(a).upper()\n \n call_count = 0\n \n # The key function returns the same result for both 'aaa' and 'azz'\n # so the cached result from the first call is returned in the second call\n assert toupper('aaa') == toupper('azz') == 'AAA'\n assert call_count == 1\n\n\n # Using cache as a key-value store\n\n cache = Cache()\n\n try:\n result = cache[1]\n except KeyError:\n result = calculate_result(1)\n cache[1] = result\n assert 1 in cache\n assert cache[1] == result\n assert cache.get(1, None) == result\n assert cache.get(2, None) is None\n\n # Cleanup\n\n import os\n\n cache = Cache(filepath='/tmp/mycache')\n cache[1] = 'one'\n assert 1 in cache\n cache.clear() # empty the cache\n assert 1 not in cache\n assert list(cache.items()) == []\n assert os.path.isfile('/tmp/mycache')\n cache.remove() # Empty the cache and remove the underlying file\n assert not os.path.isfile('/tmp/mycache')\n\nFeatures\n========\n\n- [x] Memory and file based cache.\n- [x] TTL and maxsize.\n- [x] Works with ``*args``, ``**kwargs``.\n- [x] Works with mutable function arguments of the following types: ``dict``, ``list``, ``set``.\n- [x] FIFO, LRU and LFU cache replacement policies.\n- [x] Customizable cache key function.\n- [ ] Multiprocessing- and thread-safe.\n- [ ] Pluggable external caching backends (see Redis example).\n\n.. |Build Status| image:: https://travis-ci.org/bofm/python-caching.svg?branch=master\n :target: https://travis-ci.org/bofm/python-caching\n.. |Coverage Status| image:: https://coveralls.io/repos/github/bofm/python-caching/badge.svg\n :target: https://coveralls.io/github/bofm/python-caching\n.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/caching.svg\n :target: https://pypi.python.org/pypi/caching", "description_content_type": "", "docs_url": null, "download_url": "https://github.com/bofm/python-caching/tarball/0.1.dev8", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/bofm/python-caching", "keywords": "cache,caching", "license": "", "maintainer": "", "maintainer_email": "", "name": "caching-py35", "package_url": "https://pypi.org/project/caching-py35/", "platform": "", "project_url": "https://pypi.org/project/caching-py35/", "project_urls": { "Download": "https://github.com/bofm/python-caching/tarball/0.1.dev8", "Homepage": "https://github.com/bofm/python-caching" }, "release_url": "https://pypi.org/project/caching-py35/0.1.dev8/", "requires_dist": null, "requires_python": ">=3.5", "summary": "Python utils and decorators for c\u0430ching with TTL, maxsize and file-based storage.", "version": "0.1.dev8" }, "last_serial": 4271091, "releases": { "0.1.dev8": [ { "comment_text": "", "digests": { "md5": "d77100acaff056ac85eab203ea817822", "sha256": "86548a6312da58d9ab0939d778860c4a570d3177b724d32816f819bf76804c4f" }, "downloads": -1, "filename": "caching-py35-0.1.dev8.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "d77100acaff056ac85eab203ea817822", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 10547, "upload_time": "2018-09-14T05:34:42", "url": "https://files.pythonhosted.org/packages/8b/77/5c910ab072ccbce43b66310ebe1a0cc10a2c2e8e08873c7d30111a67617b/caching-py35-0.1.dev8.linux-x86_64.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d77100acaff056ac85eab203ea817822", "sha256": "86548a6312da58d9ab0939d778860c4a570d3177b724d32816f819bf76804c4f" }, "downloads": -1, "filename": "caching-py35-0.1.dev8.linux-x86_64.tar.gz", "has_sig": false, "md5_digest": "d77100acaff056ac85eab203ea817822", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 10547, "upload_time": "2018-09-14T05:34:42", "url": "https://files.pythonhosted.org/packages/8b/77/5c910ab072ccbce43b66310ebe1a0cc10a2c2e8e08873c7d30111a67617b/caching-py35-0.1.dev8.linux-x86_64.tar.gz" } ] }