{ "info": { "author": "Ansgar Kellner", "author_email": "keans@gmx.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Build Tools" ], "description": "==============\n timecache\n==============\n\n`timecache` is a timeout-based cache implementation for Python 3.x without\nany external dependencies. Depending on the selected backend, the cache can be\nmade persistent to survive a fresh start of a script (currently, json and\npickle files are supported as backend).\n\nWarning: this is an early alpha version so the interface may change in future\nversions.\n\n\nSetup\n-----\n\nInstall `timecache` using `pip`:\n\n::\n\n pip install -U timecache\n\n\nExample\n-------\n\nA cache with a memory backend can be created as follows:\n\n::\n\n import time\n from timecache import Cache, FIVE_SECONDS\n\n # create cache with memory backend\n cache = Cache()\n\n # add a value to the cache with a default duration of 1 minute\n cache[\"one\"] = 1\n\n # add a value to the cache with a duration of 5 seconds\n cache.set(\"two\", 2, FIVE_SECONDS)\n\n print(\"two in cache: {}\".format(\"two\" in cache))\n\n # show cache entry\n print(cache)\n\n # wait for 6 s\n time.sleep(6)\n\n # show cache entry\n print(cache)\n\n print(\"two in cache: {}\".format(\"two\" in cache))\n\n\nA cache with a json file backend can be created as follows:\n\n::\n\n import time\n from timecache import Cache, JsonBackend\n\n # create cache with json backend\n cache = Cache(backend=JsonBackend())\n\n if not cache.is_existing:\n # add a value to the cache with a default duration of 1 minute\n print(\"adding new value to the cache...\")\n cache[\"one\"] = 1\n print(\"saving cache to file '{}'\".format(cache.filename))\n cache.save()\n\n # show cache entry\n print(cache)\n\nWhen calling the script again the cached value will be loaded from the\njson file.\n\n\nDecorators\n----------\n\nThere are also the three decorators `memorycache`, `jsoncache`,\n`picklecache` that allows an easy caching of function return values.\n\n\n::\n\n import time\n from timecache import jsoncache, FIVE_SECONDS\n\n\n @jsoncache(cache_filename=\"add.json\", ttl=FIVE_SECONDS)\n def add(x, y):\n return x + y\n\n\n # new cache entry\n print(add(1, 2))\n\n # new cache entry\n print(add(1, 3))\n\n # load existing cache entry\n print(add(1, 2))\n\n # wait for 6 s\n time.sleep(6)\n\n # new cache entry, since old entry has expired\n print(add(1, 2))\n\n\nDebugging\n-------\n\nTo debug the cache you can simply set the debug level.\n\n::\n\n import logging\n logging.basicConfig(level=logging.DEBUG)\n\n\nTesting\n-------\n\nFor testing additionally install `nose` and then run the tests:\n\n::\n\n pip install nose\n nosetests\n\n\nHint\n----\n\nIf you do not need a time-based cache, consider the `lru_cache` function of\nPython's `functools` module\n(https://docs.python.org/3/library/functools.html).", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com", "keywords": "python packaging", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "timecache", "package_url": "https://pypi.org/project/timecache/", "platform": "", "project_url": "https://pypi.org/project/timecache/", "project_urls": { "Homepage": "https://github.com" }, "release_url": "https://pypi.org/project/timecache/0.0.4/", "requires_dist": null, "requires_python": "", "summary": "Time Cache", "version": "0.0.4" }, "last_serial": 4231588, "releases": { "0.0.3": [ { "comment_text": "", "digests": { "md5": "f49bf905fa875f712ab02069928618f8", "sha256": "85c2abec0954dd5da2db23f616e5ed81c186a65ae5c4a819a61d38b25c47377d" }, "downloads": -1, "filename": "timecache-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "f49bf905fa875f712ab02069928618f8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7842, "upload_time": "2018-09-01T11:56:52", "url": "https://files.pythonhosted.org/packages/c1/56/0620a7494f0450851729e383764eb0398ad34427656c49727b60a27c0bfb/timecache-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f0c850d1946ac57066783ffa6d548a28", "sha256": "3ae533d7bfa92622ac203906dbd4e3669eff6b58101d5a1b5914403c40d52097" }, "downloads": -1, "filename": "timecache-0.0.3.tar.gz", "has_sig": false, "md5_digest": "f0c850d1946ac57066783ffa6d548a28", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6891, "upload_time": "2018-09-02T17:25:55", "url": "https://files.pythonhosted.org/packages/09/af/c813a53d4a7685d03da8af65e9313f3b31408bc4a0cb892d913cd8f8b6c2/timecache-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "5a1ea6e80a5fe04d10d79bf10d58b31c", "sha256": "3ba37e717977d5d0845145cdf9419aeab3e3a720c6eb5a0a23e4b5f28a1decd0" }, "downloads": -1, "filename": "timecache-0.0.4.tar.gz", "has_sig": false, "md5_digest": "5a1ea6e80a5fe04d10d79bf10d58b31c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6891, "upload_time": "2018-09-02T17:25:56", "url": "https://files.pythonhosted.org/packages/d5/cc/fbaaca1577bd43ff627bb609171e9add0967ade1351d707eed882bc9cdc1/timecache-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5a1ea6e80a5fe04d10d79bf10d58b31c", "sha256": "3ba37e717977d5d0845145cdf9419aeab3e3a720c6eb5a0a23e4b5f28a1decd0" }, "downloads": -1, "filename": "timecache-0.0.4.tar.gz", "has_sig": false, "md5_digest": "5a1ea6e80a5fe04d10d79bf10d58b31c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6891, "upload_time": "2018-09-02T17:25:56", "url": "https://files.pythonhosted.org/packages/d5/cc/fbaaca1577bd43ff627bb609171e9add0967ade1351d707eed882bc9cdc1/timecache-0.0.4.tar.gz" } ] }