{ "info": { "author": "Marcelo Moraes", "author_email": "marcelomoraesjr28@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Scrooge Cache\n=======================================\n\n[![Build Status](https://travis-ci.org/marcelomoraes28/scrooge_cache.svg?branch=master)](https://travis-ci.org/marcelomoraes28/scrooge_cache)\n[![Coverage Status](https://coveralls.io/repos/github/marcelomoraes28/scrooge_cache/badge.svg?branch=master)](https://coveralls.io/github/marcelomoraes28/scrooge_cache?branch=master)\n[![Pypi Version](https://img.shields.io/badge/pypi-0.1.2-yellow.svg)](https://img.shields.io/badge/pypi-0.1.2--beta-yellow.svg)\n[![Python Version](https://img.shields.io/badge/python-3.6%7C3.7-blue.svg)](https://img.shields.io/badge/python-3.6%7C3.7-blue.svg)\n\n![alt text](https://github.com/marcelomoraes28/scrooge_cache/raw/master/scrooge_mcduck.png)\n\nWhat is Scrooge?\n----------------------------------\n\nScrooge is a **S**mart **C**ache Sto**r**age f**o**r str**o**nger **g**entlem**e**n\n\n**Backend supports:**\n- [memcache](https://memcached.org/)\n- [redis](https://redis.io/)\n\n\nHow can I use?\n-------------\n\nScrooge is able to cache function returns based on its input arguments for a given time.\n\n**Rules:**\n- Just a unique namespace per backend instance;\n- If you do not set expiration_time scrooge will take infinite time;\n- The return of decorated function must be str or int or float or tuple, or list or dict;\n- If you use redis backend you can defined the db index using the parameter `db=index`, if you do not do this the default will be 0;\n\nInstalling\n-------------\n```\npip install scrooge-cache\n```\nQuick start\n-----------\n\n**Using with redis as backend**\n\nThis example below will cache the function return for an undetermined time\n\n```python\nimport time\nfrom scrooge import RedisBackend, Client\n\nbackend = RedisBackend(host='127.0.0.1', port=6379)\nclient = Client(cache_backend=backend)\n\n# Cached for an undetermined time\n@client.gentlemen_cache(namespace='f1')\ndef function_to_be_cached(p1, p2):\n time.sleep(5)\n return {\"p1\": p1, \"p2\": p2}\n\n# After 5 seconds the return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n\n# The return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n```\n\nThis example below will cache the function return for 10 seconds\n\n```python\nimport time\nfrom scrooge import RedisBackend, Client\n\nbackend = RedisBackend(host='127.0.0.1', port=6379)\nclient = Client(cache_backend=backend)\n\n# Cached for 10 seconds\n@client.gentlemen_cache(namespace='f1', expiration_time=10)\ndef function_to_be_cached(p1, p2):\n time.sleep(5)\n return {\"p1\": p1, \"p2\": p2}\n\n# After 5 seconds the return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n\n# The return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n\ntime.sleep(5)\n\n# After 5 seconds the return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n```\n\n**Using with memcache as backend**\n\nThis example below will cache the function return for an undetermined time\n\n```python\nimport time\nfrom scrooge import MemcacheBackend, Client\n\nbackend = MemcacheBackend(host='127.0.0.1', port=11211)\nclient = Client(cache_backend=backend)\n\n# Cached for an undetermined time\n@client.gentlemen_cache(namespace='f1')\ndef function_to_be_cached(p1, p2):\n time.sleep(5)\n return {\"p1\": p1, \"p2\": p2}\n\n# After 5 seconds the return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n\n# The return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n```\n\nThis example below will cache the function return for 10 seconds\n\n```python\nimport time\nfrom scrooge import MemcacheBackend, Client\n\nbackend = MemcacheBackend(host='127.0.0.1', port=11211)\nclient = Client(cache_backend=backend)\n\n# Cached for 10 seconds\n@client.gentlemen_cache(namespace='f1', expiration_time=10)\ndef function_to_be_cached(p1, p2):\n time.sleep(5)\n return {\"p1\": p1, \"p2\": p2}\n\n# After 5 seconds the return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n\n# The return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n\ntime.sleep(5)\n\n# After 5 seconds the return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n```\n\n**No caching**\n\nIf you wanna a cacheless request, you can do this using the `no_cache` argument\n\n```python\nimport time\nfrom scrooge import MemcacheBackend, Client\n\nbackend = MemcacheBackend(host='127.0.0.1', port=11211)\nclient = Client(cache_backend=backend)\n\n# Cached for 10 seconds\n@client.gentlemen_cache(namespace='f1', expiration_time=10)\ndef function_to_be_cached(p1, p2):\n time.sleep(5)\n return {\"p1\": p1, \"p2\": p2}\n\n# After 5 seconds the return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n\n# Cacheless request below\n# After 5 seconds the return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5, no_cache=True))\n```\n\n**Force cache update**\n\nIf you wanna force the cache update, you can do this using the `force_cache_update` argument\n\n```python\nimport time\nfrom scrooge import MemcacheBackend, Client\n\nbackend = MemcacheBackend(host='127.0.0.1', port=11211)\nclient = Client(cache_backend=backend)\n\n# Cached for 10 seconds\n@client.gentlemen_cache(namespace='f1', expiration_time=10)\ndef function_to_be_cached(p1, p2):\n time.sleep(5)\n return {\"p1\": p1, \"p2\": p2}\n\n# After 5 seconds the return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5))\n\n# Force cache update\n# After 5 seconds the return will be {\"p1\": 4, \"p2\": 5}\nprint(function_to_be_cached(4,5, force_cache_update=True))\n```\n\nRun tests\n------------\n```\npytest -ra\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/marcelomoraes28/scrooge_cache", "keywords": "cache scrooge redis memcache", "license": "", "maintainer": "", "maintainer_email": "", "name": "scrooge-cache", "package_url": "https://pypi.org/project/scrooge-cache/", "platform": "", "project_url": "https://pypi.org/project/scrooge-cache/", "project_urls": { "Homepage": "https://github.com/marcelomoraes28/scrooge_cache" }, "release_url": "https://pypi.org/project/scrooge-cache/0.1.3/", "requires_dist": null, "requires_python": "", "summary": "Scrooge Cache", "version": "0.1.3" }, "last_serial": 5427824, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "c7ca0184c7b54bce51e1f0615d741fae", "sha256": "89679cb9b98bef424aa1c35391c00a2b4de94a6cfa32258e2e26bd10e2badcc4" }, "downloads": -1, "filename": "scrooge_cache-0.0.1.tar.gz", "has_sig": false, "md5_digest": "c7ca0184c7b54bce51e1f0615d741fae", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3975, "upload_time": "2019-02-22T16:48:12", "url": "https://files.pythonhosted.org/packages/e8/3c/5c986fb26db06d00eb16968b1abea30da0991dc62f97c7ca17e6ac38d066/scrooge_cache-0.0.1.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "f86bdb0486862321d42fa6a45a0ea6a8", "sha256": "61ab77fa0c400907dccb40cacc85eec06cbd29e3d53192c3d665c32afceb51dc" }, "downloads": -1, "filename": "scrooge_cache-0.1.0.tar.gz", "has_sig": false, "md5_digest": "f86bdb0486862321d42fa6a45a0ea6a8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4160, "upload_time": "2019-02-27T20:35:58", "url": "https://files.pythonhosted.org/packages/8d/60/749ad4242d5008a83ff52768479d8997f29d42a11e44ba6b632b548ed646/scrooge_cache-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "2af60087f0abbc46b9ae253ada0ea4a8", "sha256": "1227e5836902355a161a5425b0c9304c52776adef5761e2bd9758ae698f2deef" }, "downloads": -1, "filename": "scrooge_cache-0.1.1.tar.gz", "has_sig": false, "md5_digest": "2af60087f0abbc46b9ae253ada0ea4a8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4304, "upload_time": "2019-04-25T13:22:43", "url": "https://files.pythonhosted.org/packages/69/cf/c12793de290d4758a36e5a294af60c46a88fe9e8cc0fe5d44c0187ae3cae/scrooge_cache-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "de806c302e126fe593c23bb6577eadce", "sha256": "01ce6c13ab768bf5a5b14fda14344091434a892b003ad4e9f3410daf70a96f3e" }, "downloads": -1, "filename": "scrooge_cache-0.1.2.tar.gz", "has_sig": false, "md5_digest": "de806c302e126fe593c23bb6577eadce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4261, "upload_time": "2019-06-18T23:03:12", "url": "https://files.pythonhosted.org/packages/ef/8c/eb69a007e055fcfdd72fcb259202b9456b206c77334d662eee7baadc3912/scrooge_cache-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "324290aecedf729b805a52f6e460250e", "sha256": "8681799f466ec2f0a0666f01b9031c4b35eb7263e88980bc57217c39a8afaf0d" }, "downloads": -1, "filename": "scrooge_cache-0.1.3.tar.gz", "has_sig": false, "md5_digest": "324290aecedf729b805a52f6e460250e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4260, "upload_time": "2019-06-20T22:03:58", "url": "https://files.pythonhosted.org/packages/ac/8b/361a391d32242a72f9a3469a089d5f5514f39ef9f684089e12bf1d117fcf/scrooge_cache-0.1.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "324290aecedf729b805a52f6e460250e", "sha256": "8681799f466ec2f0a0666f01b9031c4b35eb7263e88980bc57217c39a8afaf0d" }, "downloads": -1, "filename": "scrooge_cache-0.1.3.tar.gz", "has_sig": false, "md5_digest": "324290aecedf729b805a52f6e460250e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4260, "upload_time": "2019-06-20T22:03:58", "url": "https://files.pythonhosted.org/packages/ac/8b/361a391d32242a72f9a3469a089d5f5514f39ef9f684089e12bf1d117fcf/scrooge_cache-0.1.3.tar.gz" } ] }