{ "info": { "author": "daniyall", "author_email": "dev.daniyall@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "A simple decorator to cache the results of function calls.\n\nInstallation\n------------\n\n.. code:: bash\n\n pip install cache_em_all\n\nExample\n-------\n\n.. code:: python\n\n from cache_em_all import Cachable\n\n @Cachable(\"answer.json\")\n def answer_to(question):\n if question == \"life\":\n import time\n time.sleep(236500000000000)\n return 42\n\n answer_to(\"life\") # Takes 7.5 million years\n answer_to(\"life\") # Pretty much instant\n\nAfter the first call to ``answer_to``, the result of the function is\nstored in a file ``cache/answer/answer__life.json``. When the function\nis called again (with the same parameters), instead of executing the\nfunction, the decorator will get the result from the file.\n\nAdvanced usage\n--------------\n\nFile types\n~~~~~~~~~~\n\nVarious file types are supported.\n\n+--------------------------------------------+--------------------------+\n| extension | Description |\n+============================================+==========================+\n| csv | Uses pandas to save the |\n| | result in a csv file. |\n| | The return value for the |\n| | function must be a |\n| | DataFrame or Series. |\n+--------------------------------------------+--------------------------+\n| json | Saves the result in a |\n| | json file. Useful for |\n| | lists, dictionaries and |\n| | primitive types. |\n+--------------------------------------------+--------------------------+\n| pkl | Pickles the return |\n| | value. Return type can |\n| | be just about anything. |\n| | May not work well for |\n| | large (>~2GB) files |\n+--------------------------------------------+--------------------------+\n| pa | Uses pyarrow to save |\n| | files. This is generally |\n| | faster than pkl and |\n| | supports larger files |\n| | (tested up to 50GB) |\n+--------------------------------------------+--------------------------+\n\nVersioning\n~~~~~~~~~~\n\nThe ``Cachable`` decorator can accept a version number. This is useful\nfor when you update a function. For example,\n\nYou had the following code:\n\n.. code:: python\n\n from cache_em_all import Cachable\n\n @Cachable(\"add.json\")\n def add(x, y):\n return x + x\n\nThis is a bug (should be ``x+y``, not ``x+x``), but you\u2019ve run this\nfunction multiple times and there are lots of cached results. Rather\nthan manually deleting the cache folder, you can bump the version number\n(version numbers start at 0).\n\n.. code:: python\n\n from cache_em_all import Cachable\n\n @Cachable(\"add.json\", version=1)\n def add(x, y):\n return x + y\n\nNow next time the function is called it will invalidate the cache and\nre-run the function.\n\nDo not use this feature in multi-processing code because the writes to\nthe version file do not (yet) use locks.\n\nFolder\n~~~~~~\n\nBy default all cached files are stored in a folder called ``cache``.\nThis can be changed for each function by passing ``folder`` to\n``Cachable``.\n\n.. code:: python\n\n from cache_em_all import Cachable\n\n @Cachable(\"add.json\", folder=\"/mnt/ram/fastcache\")\n def add(x, y):\n return x + y\n\nYou can also change the default cache dir so that all cache files are by\ndefault saved elsewhere.\n\n.. code:: python\n\n from cache_em_all import Cachable, set_cache_dir\n set_cache_dir(\"/mnt/huge_hdd\")\n\n @Cachable(\"add.json\")\n def add(x, y):\n return x + y\n\nDisable cache\n~~~~~~~~~~~~~\n\nYou can also disable the cache by setting ``use`` to ``False``.\n\n.. code:: python\n\n from cache_em_all import Cachable\n\n @Cachable(\"add.json\", use=False)\n def add(x, y):\n return x + y\n\nThis can be useful for debugging or optmizing the function.", "description_content_type": "", "docs_url": null, "download_url": "https://github.com/daniyall/cache_em_all/archive/0.2.2.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/daniyall/cache_em_all", "keywords": "cache,cachable,save,intermediate", "license": "LICENSE", "maintainer": "", "maintainer_email": "", "name": "cache-em-all", "package_url": "https://pypi.org/project/cache-em-all/", "platform": "", "project_url": "https://pypi.org/project/cache-em-all/", "project_urls": { "Download": "https://github.com/daniyall/cache_em_all/archive/0.2.2.tar.gz", "Homepage": "https://github.com/daniyall/cache_em_all" }, "release_url": "https://pypi.org/project/cache-em-all/0.2.2/", "requires_dist": null, "requires_python": "", "summary": "A simple decorator to cache the results of functions", "version": "0.2.2" }, "last_serial": 4782729, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "b47e1b458c6c297f79795d3eff066086", "sha256": "1a36ac166c3f3a930846df3b4182d7573660bf796dcd34ee6d32d61f6fb01261" }, "downloads": -1, "filename": "cache-em-all-0.2.tar.gz", "has_sig": false, "md5_digest": "b47e1b458c6c297f79795d3eff066086", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16224, "upload_time": "2019-02-05T03:39:38", "url": "https://files.pythonhosted.org/packages/41/9b/ab40a759d0081b3c4a34c98ed90a0e0a47e30fcf1e173bc0c6230b803dbe/cache-em-all-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "98933252b353c962dd59d47820830460", "sha256": "2d1d6285b44569142cbc0518af4cd5a6847e328ce866e12bd8917c75ae1418eb" }, "downloads": -1, "filename": "cache-em-all-0.2.1.tar.gz", "has_sig": false, "md5_digest": "98933252b353c962dd59d47820830460", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16370, "upload_time": "2019-02-05T03:48:07", "url": "https://files.pythonhosted.org/packages/18/a0/110455f5b9c23d02bed26c1c0b4979200e55885e860abb6851c6047c0dc7/cache-em-all-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "a4424fa082b2dc5a8a83b64eee027d37", "sha256": "db24478b027a3c096f3fe0cd7dd2c85817d8fb697b04610bdde0e07d57460868" }, "downloads": -1, "filename": "cache-em-all-0.2.2.tar.gz", "has_sig": false, "md5_digest": "a4424fa082b2dc5a8a83b64eee027d37", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16598, "upload_time": "2019-02-05T15:59:10", "url": "https://files.pythonhosted.org/packages/d3/92/6e01eba792c5d1895430ee214c06ef24934f16254d72013499412b1c0c25/cache-em-all-0.2.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a4424fa082b2dc5a8a83b64eee027d37", "sha256": "db24478b027a3c096f3fe0cd7dd2c85817d8fb697b04610bdde0e07d57460868" }, "downloads": -1, "filename": "cache-em-all-0.2.2.tar.gz", "has_sig": false, "md5_digest": "a4424fa082b2dc5a8a83b64eee027d37", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16598, "upload_time": "2019-02-05T15:59:10", "url": "https://files.pythonhosted.org/packages/d3/92/6e01eba792c5d1895430ee214c06ef24934f16254d72013499412b1c0c25/cache-em-all-0.2.2.tar.gz" } ] }