{ "info": { "author": "Fan Jindong", "author_email": "765912710@qq.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "pycached\n########\n\ncache supporting multiple backends (memory, redis).\nSynchronization library based on aiocache.\n\n.. image:: https://travis-ci.org/fanjindong/pycached.svg?branch=master\n :target: https://travis-ci.org/fanjindong/pycached\n\n.. image:: https://codecov.io/gh/fanjindong/pycached/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/fanjindong/pycached\n\n.. image:: https://badge.fury.io/py/pycached.svg\n :target: https://pypi.python.org/pypi/pycached\n\n.. image:: https://img.shields.io/pypi/pyversions/pycached.svg\n :target: https://pypi.python.org/pypi/pycached\n\n.. image:: https://api.codacy.com/project/badge/Grade/96f772e38e63489ca884dbaf6e9fb7fd\n :target: https://www.codacy.com/app/fanjindong/pycached\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/ambv/black\n\nThis library aims for simplicity over specialization. All caches contain the same minimum interface which consists on the following functions:\n\n- ``add``: Only adds key/value if key does not exist.\n- ``get``: Retrieve value identified by key.\n- ``set``: Sets key/value.\n- ``multi_get``: Retrieves multiple key/values.\n- ``multi_set``: Sets multiple key/values.\n- ``exists``: Returns True if key exists False otherwise.\n- ``increment``: Increment the value stored in the given key.\n- ``delete``: Deletes key and returns number of deleted items.\n- ``clear``: Clears the items stored.\n- ``raw``: Executes the specified command using the underlying client.\n\n\n.. role:: python(code)\n :language: python\n\n.. contents::\n\n.. section-numbering:\n\n\nInstalling\n==========\n\n- ``pip install pycached``\n- ``pip install pycached[redis]``\n- ``pip install pycached[msgpack]``\n\n\nUsage\n=====\n\nUsing a cache is as simple as\n\n.. code-block:: python\n\n >>> from from pycached import Cache\n >>> cache = Cache(Cache.MEMORY) # Here you can also use Cache.REDIS and Cache.MEMCACHED, default is Cache.MEMORY\n >>> cache.set('key', 'value')\n True\n >>> cache.get('key')\n 'value'\n\nOr as a decorator\n\n.. code-block:: python\n\n import time\n\n from collections import namedtuple\n\n from pycached import cached, Cache, RedisCache\n from pycached.serializers import PickleSerializer\n # With this we can store python objects in backends like Redis!\n\n Result = namedtuple('Result', \"content, status\")\n\n\n @cached(ttl=10, cache=RedisCache, key=\"key\", serializer=PickleSerializer(), port=6379, namespace=\"main\")\n def cached_call():\n print(\"Sleeping for three seconds zzzz.....\")\n time.sleep(3)\n return Result(\"content\", 200)\n\n\n def run():\n cached_call()\n cached_call()\n cached_call()\n cache = Cache(Cache.REDIS, endpoint=\"127.0.0.1\", port=6379, namespace=\"main\")\n cache.delete(\"key\")\n\n if __name__ == \"__main__\":\n run()\n\nThe recommended approach to instantiate a new cache is using the `Cache` constructor. However you can also instantiate directly using `pycached.RedisCache`, `pycached.SimpleMemoryCache`.\n\n\nYou can also setup cache aliases so its easy to reuse configurations\n\n.. code-block:: python\n\n from pycached import caches\n\n # You can use either classes or strings for referencing classes\n caches.set_config({\n 'default': {\n 'cache': \"pycached.SimpleMemoryCache\",\n 'serializer': {\n 'class': \"pycached.serializers.StringSerializer\"\n }\n },\n 'redis_alt': {\n 'cache': \"pycached.RedisCache\",\n 'endpoint': \"127.0.0.1\",\n 'port': 6379,\n 'timeout': 1,\n 'serializer': {\n 'class': \"pycached.serializers.PickleSerializer\"\n },\n 'plugins': [\n {'class': \"pycached.plugins.HitMissRatioPlugin\"},\n {'class': \"pycached.plugins.TimingPlugin\"}\n ]\n }\n })\n\n\n def default_cache():\n cache = caches.get('default') # This always returns the SAME instance\n cache.set(\"key\", \"value\")\n assert cache.get(\"key\") == \"value\"\n\n\n def alt_cache():\n cache = caches.create('redis_alt') # This creates a NEW instance on every call\n cache.set(\"key\", \"value\")\n assert cache.get(\"key\") == \"value\"\n\n\n def test_alias():\n default_cache()\n alt_cache()\n\n caches.get('redis_alt').delete(\"key\")\n\n\n if __name__ == \"__main__\":\n test_alias()\n\n\nHow does it work\n================\n\nPycached provides 3 main entities:\n\n- **backends**: Allow you specify which backend you want to use for your cache. Currently supporting: SimpleMemoryCache, RedisCache using redis_.\n- **serializers**: Serialize and deserialize the data between your code and the backends. This allows you to save any Python object into your cache. Currently supporting: StringSerializer, PickleSerializer, JsonSerializer, and MsgPackSerializer. But you can also build custom ones.\n- **plugins**: Implement a hooks system that allows to execute extra behavior before and after of each command.\n\n If you are missing an implementation of backend, serializer or plugin you think it could be interesting for the package, do not hesitate to open a new issue.\n\n.. image:: docs/images/architecture.png\n :align: center\n\nThose 3 entities combine during some of the cache operations to apply the desired command (backend), data transformation (serializer) and pre/post hooks (plugins). To have a better vision of what happens, here you can check how ``set`` function works in ``pycached``:\n\n.. image:: docs/images/set_operation_flow.png\n :align: center\n\n\nAmazing examples\n================\n\nIn `examples folder `_ you can check different use cases:\n\n- `Sanic, Aiohttp and Tornado `_\n- `Python object in Redis `_\n- `Custom serializer for compressing data `_\n- `TimingPlugin and HitMissRatioPlugin demos `_\n- `Using marshmallow as a serializer `_\n- `Using cached decorator `_.\n- `Using multi_cached decorator `_.\n\n\n\nDocumentation\n=============\n\n- `Usage `_\n- `Caches `_\n- `Serializers `_\n- `Plugins `_\n- `Configuration `_\n- `Decorators `_\n- `Testing `_\n- `Examples `_\n\n\n.. _redis: https://github.com/andymccurdy/redis-py", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/fanjindong/pycached", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "pycached", "package_url": "https://pypi.org/project/pycached/", "platform": "", "project_url": "https://pypi.org/project/pycached/", "project_urls": { "Homepage": "https://github.com/fanjindong/pycached" }, "release_url": "https://pypi.org/project/pycached/0.0.9/", "requires_dist": null, "requires_python": "", "summary": "multi backend cache", "version": "0.0.9" }, "last_serial": 5241178, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "b38b8bb925e3a76b3baa7b0a94e12701", "sha256": "12838f3bc3b5b5e9ca1842ddacdffcde904ebc2f5fd2ccf0c4bd181f11f6a6c1" }, "downloads": -1, "filename": "pycached-0.0.1.tar.gz", "has_sig": false, "md5_digest": "b38b8bb925e3a76b3baa7b0a94e12701", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20851, "upload_time": "2019-04-04T02:13:48", "url": "https://files.pythonhosted.org/packages/5b/49/f13fe7e3099d1addd8b67d9079c8eb824df66e2333f096b47037582b9ebb/pycached-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "456ba1a4e910ef626242d1d90a81e4a0", "sha256": "96b80d0f2d19525f9dc08a33b10c80c5ab057a517b39cccee2552d21b89a6d0a" }, "downloads": -1, "filename": "pycached-0.0.2.tar.gz", "has_sig": false, "md5_digest": "456ba1a4e910ef626242d1d90a81e4a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20870, "upload_time": "2019-04-04T09:16:13", "url": "https://files.pythonhosted.org/packages/15/0b/1a2e9742624c04f15b8f94cfd6973eb3a9965bdd07654408757293a7cad6/pycached-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "0029ec864b4ba4164f4a036beda75293", "sha256": "381fd4ad227e4538cd7a10921022739a7a791db016043045df6c05fe5e23fe02" }, "downloads": -1, "filename": "pycached-0.0.3.tar.gz", "has_sig": false, "md5_digest": "0029ec864b4ba4164f4a036beda75293", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20611, "upload_time": "2019-04-07T10:24:22", "url": "https://files.pythonhosted.org/packages/e5/d5/774bc81365123ad4172952cf2047973a19e663409d92c2930de978691579/pycached-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "64473484261dff1dd6e4c0368fd1d2e4", "sha256": "4db5254a9cf16abdd6bc9d103a524b2be431155914bedaea978c76cb2a06959a" }, "downloads": -1, "filename": "pycached-0.0.4.tar.gz", "has_sig": false, "md5_digest": "64473484261dff1dd6e4c0368fd1d2e4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 35263, "upload_time": "2019-04-10T09:18:52", "url": "https://files.pythonhosted.org/packages/cc/9d/cf4b8be5f8eeb2aa3ec987e56998915fffc1c24074283e9d25f8ecbfedac/pycached-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "6d445b2cd484dd3e64a14123d22115bb", "sha256": "89226141bac874cf1fa32b8753548f122b09d566e9bf8b89c6dad75f138dd8a8" }, "downloads": -1, "filename": "pycached-0.0.5.tar.gz", "has_sig": false, "md5_digest": "6d445b2cd484dd3e64a14123d22115bb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 28765, "upload_time": "2019-04-22T03:30:45", "url": "https://files.pythonhosted.org/packages/ef/c6/2e264a5ddfe428036a037a2a62ba96a2f167376c81ba00367e7afe4b1d23/pycached-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "53312e0b9267db69b64286385f486d0b", "sha256": "d42367ac217af66b4605cb8f27bebd31311de73a6f635bb9b24c2511da66a977" }, "downloads": -1, "filename": "pycached-0.0.6.tar.gz", "has_sig": false, "md5_digest": "53312e0b9267db69b64286385f486d0b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 28816, "upload_time": "2019-04-25T12:11:55", "url": "https://files.pythonhosted.org/packages/83/11/e9aed3678d59946701f2be67fdc5e8a6d6119393dc55953f8821fcf8920b/pycached-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "edc503b44acac6229a86ca94296ee8af", "sha256": "e9b6b4aa5239080b511c6ae5f080eea6282e1a663b12d34c3ce91069b76383a8" }, "downloads": -1, "filename": "pycached-0.0.7.tar.gz", "has_sig": false, "md5_digest": "edc503b44acac6229a86ca94296ee8af", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29665, "upload_time": "2019-05-06T07:57:20", "url": "https://files.pythonhosted.org/packages/2f/48/ae593d61478b05645cf8ede1247752770fe663abc92fe7cd09d17a82ca02/pycached-0.0.7.tar.gz" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "b08a17b6cd3688b27c92bdb74eb60ea9", "sha256": "336721eefaf66f682531ed2e9a57b406a80b673d552e3e8a9fea33d22f5ffffb" }, "downloads": -1, "filename": "pycached-0.0.9.tar.gz", "has_sig": false, "md5_digest": "b08a17b6cd3688b27c92bdb74eb60ea9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29627, "upload_time": "2019-05-08T03:12:18", "url": "https://files.pythonhosted.org/packages/63/b0/3598a3a1a946436d16503a373a971efd9c76f6bef59e64c1c0980aefe45b/pycached-0.0.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b08a17b6cd3688b27c92bdb74eb60ea9", "sha256": "336721eefaf66f682531ed2e9a57b406a80b673d552e3e8a9fea33d22f5ffffb" }, "downloads": -1, "filename": "pycached-0.0.9.tar.gz", "has_sig": false, "md5_digest": "b08a17b6cd3688b27c92bdb74eb60ea9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29627, "upload_time": "2019-05-08T03:12:18", "url": "https://files.pythonhosted.org/packages/63/b0/3598a3a1a946436d16503a373a971efd9c76f6bef59e64c1c0980aefe45b/pycached-0.0.9.tar.gz" } ] }