{ "info": { "author": "Dmitry Kislov", "author_email": "kislov@easydan.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development" ], "description": "Caching results of functions in Python\n======================================\n\n.. image:: https://travis-ci.com/scidam/cachepy.svg?branch=dev\n :target: https://travis-ci.com/scidam/cachepy\n\n\nA caching toolset for Python. It is tested for both\nPython 2.7.x and 3.4+ (<3.8).\n\nFeatures\n--------\n\n * Memory-based and file-based caches;\n * Ability to set the TTL (time-to-live) and NOC (the number of calls) on caches;\n * Encryption of the cached data (symmetric encryption algorithm (RSA) is used);\n * LFU (least frequently used) and MFU (most frequently used) cache-clearing strategies;\n * caches of limited size;\n\nNotes\n-----\n\n - Encryption functionality requires the `PyCryptodome` package to be installed;\n - File-based caches save the cached data in a file; files with cached data should be\n cleaned up manually, if needed.\n\nExamples\n--------\n\n.. code-block:: python\n\n from cachepy import *\n\n mycache = Cache()\n # save the cached data to memory without encryption\n\n @mycache\n def my_heavy_function(x):\n '''Performs heavy computations'''\n\n print('Hi, I am called...')\n return x**2\n\n my_heavy_function(2)\n # \"Hi, I am called...\" will be printed to stdout only once\n # return 4\n\n my_heavy_function(2)\n # return 4\n\n\nTo store data to a file, one needs to initialize a decorator, as follows:\n\n.. code-block:: python\n\n # create cache-to-file decorator\n filecache = FileCache('mycache') # mycache.dat file will be created;\n # `.dat` extension is appended automatically to the filename\n # (depends on the shelve module implementation);\n\nIts behavior is the same as a memory-based one, but all cached data is stored in\nthe specified file.\n\nOne can set up time-to-live (TTL) and/or maximum number of calls (NOC)\nfor the cached data when the decorator is initialized:\n\n.. code-block:: python\n\n import time\n from cachepy import *\n\n cache_with_ttl = Cache(ttl=2) # ttl given in seconds\n\n @cache_with_ttl\n def my_heavy_function(x):\n '''Performs heavy computations'''\n\n print('Hi, I am called...')\n return x**2\n\n my_heavy_function(3)\n # Hi, I am called... will be printed\n # return 9\n my_heavy_function(3)\n # 'Hi, I am called ...' will not be printed\n # return 9\n time.sleep(2)\n my_heavy_function(3)\n # 'Hi, I am called ...' will be printed again\n # return 9\n\n\n.. code-block:: python\n\n cache_with_noc = Cache(noc=2) # the number-of-calls: noc = 2\n\n @cache_with_noc\n def my_heavy_function(x):\n '''Performs heavy computations'''\n\n print('Hi, I am called...')\n return x**2\n\n my_heavy_function(3)\n my_heavy_function(3) # 'Hi, I am called ...' will not be printed\n my_heavy_function(3) # 'Hi, I am called ...' will be printed again\n\n\nIt is easy to use both `NOC` and `TTL` arguments when defining\na caching decorator:\n\n.. code-block:: python\n\n cache_with_noc_ttl = Cache(noc=2, ttl=1)\n\n @cache_with_noc_ttl\n def my_heavy_function(x):\n '''Performs heavy computations'''\n\n print('Hi, I am called...')\n return x**2\n\n my_heavy_function(3)\n my_heavy_function(3) # 'Hi, I am called ...' will not be printed\n my_heavy_function(3) # 'Hi, I am called ...' will be printed (noc is\n # reached, recompute the func value)\n time.sleep(2) # get ttl expired\n my_heavy_function(3) # 'Hi, I am called ...' will be printed again\n\nOne can encrypt the cached data by providing a non-empty `key` argument as\na password (RSA encryption algorithm is used):\n\n.. code-block:: python\n\n cache_to_file_ttl_noc = FileCache('mycache',\n noc=2, ttl = 2,\n key='mypassword')\n\n @cache_to_file_ttl_noc\n def my_heavy_function(x):\n '''Performs heavy computations'''\n\n print('Hi, I am called...')\n return x**2\n\n my_heavy_function(2) # 'Hi, I am called...' will be printed\n my_heavy_function(2) # 'Hi, I am called...' will not be printed\n\nWhen `my_heavy_function` is decorated by `cache_to_file_ttl_noc`, as shown\nin the example above, the value `2**2 = 4` will be computed and the result of\nthe computation will be stored in the file named `mycache.dat`. Along\nwith the result of the computation, additional information will be stored\nin the file `mycache.dat`. The additional information includes:\n1) the result's expiration time (computed from the TTL), \n2) NOC and 3) the number of already performed calls of the function being\ndecorated (`my_heavy_function`).\n\nEncryption is available only if `PyCryptodome` package is installed and the\n`key` parameter (a non-empty string representing the password) is passed to the\ncache constructor. It also could work with the old PyCrypto package.\n\nIf you passed the non-empty `key` parameter to the cache constructor\nbut `PyCryptodome` was not found, a special warning would be raised in this case\n(\"PyCryptodome not installed. Data will not be encrypted\") and\nthe cache would work as usual but without encryption functionality.\n\n\nCaching with limitations\n------------------------\n\nStandard cache constructors are used to initialize caches of unlimited capacity.\nThere are also caches of limited capacity.\nSuch caches are initialized by constructors named `LimitedCache` and `LimitedFileCache`.\nThese constructors have additional\nparameters `cache_size` (the maximum number of items stored in the cache) and\n`algorithm` (cache-clearing algorithm). Available `algorithm` values are\n`lfu` (default, which stands for least frequently used) and `mfu` (most frequently used).\nWhen `algorithm='lfu'`, then the least frequently used item is removed from the cache,\nif it is exhausted. In case of `algorithm='mfu'`, everything behaves the same way,\nwith the only difference being that the most frequently used item is removed.\n\n\nTesting\n-------\n\n.. code-block:: bash\n\n python -m cachepy.test\n\n\nTODO\n----\n\n * Writing backend for redis server\n\n\nLog list\n--------\n\n * Version 1.1\n * Version 1.0 (broken installation via pip/pipenv)\n * Version 0.1\n - initial release\n\n\nAuthor\n------\n\n Dmitry Kislov \n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/scidam/cachepy", "keywords": "caching,python,file-based cache,memory-based cache,encrypted cache", "license": "", "maintainer": "", "maintainer_email": "", "name": "cachepy", "package_url": "https://pypi.org/project/cachepy/", "platform": "", "project_url": "https://pypi.org/project/cachepy/", "project_urls": { "Homepage": "https://github.com/scidam/cachepy" }, "release_url": "https://pypi.org/project/cachepy/1.1/", "requires_dist": null, "requires_python": "", "summary": "Caching results of functions in Python", "version": "1.1" }, "last_serial": 5454427, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "55f882f518fdc01c2c07f7574693de06", "sha256": "e8e682940ba46d5676e3520cfb12da2f74ac5e48927e001c787dc1adfec53330" }, "downloads": -1, "filename": "cachepy-0.1.tar.gz", "has_sig": false, "md5_digest": "55f882f518fdc01c2c07f7574693de06", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8319, "upload_time": "2016-03-31T05:30:45", "url": "https://files.pythonhosted.org/packages/46/9e/65ed8ae85bda45130f7d8b76f334b3538ea3f95958742d05f0a10da0360d/cachepy-0.1.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "1c9c6c6e576f0f2f1a942e8e4292ad4a", "sha256": "b4aff37a63d348f158fc3cae67819f765faeeb228c635bf38cc24246b0508b72" }, "downloads": -1, "filename": "cachepy-1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "1c9c6c6e576f0f2f1a942e8e4292ad4a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21156, "upload_time": "2019-06-23T05:34:27", "url": "https://files.pythonhosted.org/packages/01/d7/716ee93c48d76f70eedbdf8f302f92cceda90ade50c153984d26e59ebf35/cachepy-1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a6993f9b67eb5faf5a4ade20dbcc6004", "sha256": "a404fe424d02b09c009e9683bbd9fd9841b02b07e4064354e8918780cd1e4435" }, "downloads": -1, "filename": "cachepy-1.0.tar.gz", "has_sig": false, "md5_digest": "a6993f9b67eb5faf5a4ade20dbcc6004", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11993, "upload_time": "2019-06-23T05:34:29", "url": "https://files.pythonhosted.org/packages/e3/e6/e8e692bd455cab24b668efb934143a4bf6d46a9a13b080bc233386305fac/cachepy-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "29fcbbe6b3a6718f24da585ffc98371d", "sha256": "5813fec3cf831cb98ff9550e0124e30b6bd13fe1e8d534c59f36709f81fa0416" }, "downloads": -1, "filename": "cachepy-1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "29fcbbe6b3a6718f24da585ffc98371d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 18485, "upload_time": "2019-06-27T00:27:34", "url": "https://files.pythonhosted.org/packages/19/8f/86bc034dcd2d425c9175bc942b28b335a4068be86d219f4838b742cab2ee/cachepy-1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0f4c1f9be2c42e16cc7e1b661f2ad82b", "sha256": "0e14058a6807fcec856de459c0610f9a2a04d843acb7ff3488b2322380b0e0e9" }, "downloads": -1, "filename": "cachepy-1.1.tar.gz", "has_sig": false, "md5_digest": "0f4c1f9be2c42e16cc7e1b661f2ad82b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13819, "upload_time": "2019-06-27T00:27:37", "url": "https://files.pythonhosted.org/packages/a9/d9/474d3f442af745ce9021dd1085ae9a669b7988eb076d3c3130ed1b52ae90/cachepy-1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "29fcbbe6b3a6718f24da585ffc98371d", "sha256": "5813fec3cf831cb98ff9550e0124e30b6bd13fe1e8d534c59f36709f81fa0416" }, "downloads": -1, "filename": "cachepy-1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "29fcbbe6b3a6718f24da585ffc98371d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 18485, "upload_time": "2019-06-27T00:27:34", "url": "https://files.pythonhosted.org/packages/19/8f/86bc034dcd2d425c9175bc942b28b335a4068be86d219f4838b742cab2ee/cachepy-1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0f4c1f9be2c42e16cc7e1b661f2ad82b", "sha256": "0e14058a6807fcec856de459c0610f9a2a04d843acb7ff3488b2322380b0e0e9" }, "downloads": -1, "filename": "cachepy-1.1.tar.gz", "has_sig": false, "md5_digest": "0f4c1f9be2c42e16cc7e1b661f2ad82b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13819, "upload_time": "2019-06-27T00:27:37", "url": "https://files.pythonhosted.org/packages/a9/d9/474d3f442af745ce9021dd1085ae9a669b7988eb076d3c3130ed1b52ae90/cachepy-1.1.tar.gz" } ] }