{ "info": { "author": "Jay Marcyes", "author_email": "jay@marcyes.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Topic :: Database", "Topic :: Software Development :: Libraries", "Topic :: Utilities" ], "description": "Caches\n======\n\nA Python caching library that gives a similar interface to standard\nPython data structures like Dict and Set but is backed by redis.\n\nCaches was lovingly crafted for `First\nOpinion `__.\n\nHow to use\n----------\n\nCaches can only use `Redis `__.\n\nCaches relies on setting the environment variable ``CACHES_DSN``:\n\n::\n\n caches.interface.Redis://localhost/0\n\nIf you want to cache things using more than one redis server, you can\nactually set multiple environment variables:\n\n::\n\n export CACHES_DSN_1=caches.interface.Redis://somedomain.com/0#redis1\n export CACHES_DSN_2=caches.interface.Redis://someotherdomain.com/0#redis2\n\nAfter you've set the environment variable, then you just need to import\ncaches in your code:\n\n.. code:: python\n\n import caches\n\nCaches will take care of parsing the url and creating the redis\nconnection, automatically, so after the import Caches will be ready to\nuse.\n\nInterface\n~~~~~~~~~\n\nAll caches caching classes have a similar interface, they take the\npassed in constructor ``*args`` and concat them to create a key:\n\n.. code:: python\n\n c = KeyCache('foo', 'bar', 'che')\n print c.key # foo.bar.che\n\nIf you would like to init your cache object with a value, use the\n``data`` ``**kwarg``:\n\n.. code:: python\n\n c = KeyCache('foo', data=\"boom!\")\n print c.key # foo\n print c # \"boom!\"\n\nEach caches base caching class is meant to be extended so you can set\nsome parameters:\n\n- **serialize** -- boolean -- True if you want all values pickled,\n False if you don't (ie, you're caching ints or strings or something).\n\n- **prefix** -- string -- This will be prepended to the key args you\n pass into the constructor.\n\n- **ttl** -- integer -- time to live, how many seconds to cache the\n value. Set to like 2 hours by default, 0 means live forevor.\n\n- **connection\\_name** -- string -- if you have more than one caches\n dsn then you can use this to set the name of the connection you want\n (the name of the connection is the ``#connection_name`` fragment of a\n dsn url).\n\n.. code:: python\n\n class MyIntCache(KeyCache):\n serialize = False # don't bother to serialize values since we're storing ints\n prefix = \"MyIntCache\" # every key will have this prefix, change to invalidate all currently cached values\n ttl = 7200 # store each int for 2 hours\n\nCache Classes\n~~~~~~~~~~~~~\n\nKeyCache\n^^^^^^^^\n\nThis is the traditional caching object, it sets a value into a key:\n\n.. code:: python\n\n c = KeyCache('foo')\n c.data = 5 # cache 5\n c += 10 # increment 5 by 10, store 15 in the cache\n\n c.clear()\n print c # None\n\nDictCache\n^^^^^^^^^\n\nThis caching object acts more or less like a Python\n`dictionary `__:\n\n.. code:: python\n\n c = DictCache('foo')\n c['bar'] = 'b'\n c['che'] = 'c'\n for key, val in c.iteritems():\n print key, val # will print bar b and then che c\n\nSetCache\n^^^^^^^^\n\nThis caching object acts more or less like a Python\n`set `__:\n\n.. code:: python\n\n c = SetCache('foo')\n c.add('bar')\n c.add('che')\n print 'che' in c # True\n\nSortedSetCache\n^^^^^^^^^^^^^^\n\nThis caching object acts more or less like a Python\n`set `__ but has\nsome changes:\n\n- The add() method can take a score value\n- The pop() method will pop off the lowest score from the set, and pops\n a tuple: (elem, score)\n- An rpop() method allows you to pop the highest score from the set.\n- Iterating through the set results in tuples of (elem, score), not\n just elem like in a normal set or the ``SetCache``.\n- The chunk(limit, offset) and rchunk(limit, offset) methods will work\n through sections of the list working either forwards or backwards.\n\n.. code:: python\n\n c = SortedSetCache('foo')\n c.add('bar', 1)\n c.add('che', 10)\n print 'che' in c # True\n print c.pop() # (bar, 1)\n\nCounterCache\n^^^^^^^^^^^^\n\nThis caching object acts more or less like a Python\n`collections.Counter `__:\n\n.. code:: python\n\n c = CounterCache('foo')\n c['bar'] = 5\n c['bar'] += 5\n\n print c['bar'] # 10\n\nDecorator\n~~~~~~~~~\n\nCaches exposes a decorator to make caching the return value of a\nfunction easy. This only works for ``KeyCache`` derived caching.\n\nThe ``cached`` decorator can accept a caching class and also a key\nfunction (similar to the python `built-in ``sorted()``\nfunction `__ key\nargument), except caches key argument returns a list that can be passed\nto the constructor of the caching class as ``*args``.\n\n.. code:: python\n\n from caches import KeyCache\n\n @KeyCache.cached(key=\"some_cache_key\")\n def foo(*args):\n return reduce(lambda x, y: x+y, args)\n\n foo(1, 2) # will compute the value and cache the return value\n foo(1, 2) # return value from cache\n\n foo(1, 2, 3) # uh-oh, wrong value, our key was too static\n\nLet's try again, this time with a dynamic key\n\n.. code:: python\n\n @KeyCache.cached(key=lambda *args: args)\n def foo(*args):\n return reduce(lambda x, y: x+y, args)\n\n foo(1, 2) # compute and cache, key func returned [1, 2]\n foo(1, 2) # grabbed from cache\n foo(1, 2, 3) # compute and cache because our key func returned [1, 2, 3]\n\nWhat about custom caches classes?\n\n.. code:: python\n\n class CustomCache(KeyCache): pass\n\n @CustomCache.cached(key=lambda *args: args)\n def foo(*args):\n return reduce(lambda x, y: x+y, args)\n\nInstall\n-------\n\nUse pip from pypi:\n\n::\n\n pip install caches\n\nor from source using pip:\n\n::\n\n pip install git+https://github.com/firstopinion/caches#egg=caches\n\nAcknowledgements\n----------------\n\nCaches uses the very cool `redis\\_collections\nmodule `__.\n\nSome of the interface is inspired from a module that `Ryan\nJohnson `__ wrote for Undrip.\n\nLicense\n-------\n\nMIT\n\nOther links\n-----------\n\n`Dogpile `__\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/firstopinion/caches", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "caches", "package_url": "https://pypi.org/project/caches/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/caches/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/firstopinion/caches" }, "release_url": "https://pypi.org/project/caches/0.2.18/", "requires_dist": null, "requires_python": null, "summary": "Python caching backed by Redis", "version": "0.2.18" }, "last_serial": 1358179, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "73ca6fc252210a18919db7561563b9e5", "sha256": "eb942543b3d2e2eb12c34f001f6ea6dc03f940d6961bf41ca68f413e89729840" }, "downloads": -1, "filename": "caches-0.1.1.tar.gz", "has_sig": false, "md5_digest": "73ca6fc252210a18919db7561563b9e5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4276, "upload_time": "2013-09-17T02:57:24", "url": "https://files.pythonhosted.org/packages/2f/8e/3b57808b6dee67a9493d039fc6640010db5358a62c5ba8c73d450c7a6dc4/caches-0.1.1.tar.gz" } ], "0.2.10": [ { "comment_text": "", "digests": { "md5": "6d1b712f273069617f2958e3d4de0276", "sha256": "84e5b0d1b57b3f1914c5eef921e2724a25605e2d085e9d985f0aefc9b6b4f866" }, "downloads": -1, "filename": "caches-0.2.10.tar.gz", "has_sig": false, "md5_digest": "6d1b712f273069617f2958e3d4de0276", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10031, "upload_time": "2014-01-28T00:19:43", "url": "https://files.pythonhosted.org/packages/7f/79/4c6ae4ba0f75de8a5d94ec690030f4afc8321dacee36b41996294f4963c0/caches-0.2.10.tar.gz" } ], "0.2.11": [ { "comment_text": "", "digests": { "md5": "1695c178cccb5ad690690d1bd07aa602", "sha256": "b50311a9e13ac93b908cd2f597b6b176df778c9562e9a15d26448cbff8739ef4" }, "downloads": -1, "filename": "caches-0.2.11.tar.gz", "has_sig": false, "md5_digest": "1695c178cccb5ad690690d1bd07aa602", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10157, "upload_time": "2014-02-11T00:25:40", "url": "https://files.pythonhosted.org/packages/c2/c3/736c1b4514d7663ab49250d3fae358fe97dc95f4c675abb0cbed4f6b4a65/caches-0.2.11.tar.gz" } ], "0.2.12": [ { "comment_text": "", "digests": { "md5": "be662b731256c985a27e1caf667c6ea8", "sha256": "347caf1ea9eb7cece0c109d556883f3a5f143b49261fbeb25f8641d7e01a0015" }, "downloads": -1, "filename": "caches-0.2.12.tar.gz", "has_sig": false, "md5_digest": "be662b731256c985a27e1caf667c6ea8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10428, "upload_time": "2014-02-18T01:20:26", "url": "https://files.pythonhosted.org/packages/02/15/d12cad6e7945cbffb0c1a1f1e92fde8d5df0ca89ff8458898fdac349c048/caches-0.2.12.tar.gz" } ], "0.2.13": [ { "comment_text": "", "digests": { "md5": "b6508425eef61568a7521d895e7b8470", "sha256": "8bbc5055d229e72e0937359d094eb42ea76820bbf0758813e1940aa0be690a4f" }, "downloads": -1, "filename": "caches-0.2.13.tar.gz", "has_sig": false, "md5_digest": "b6508425eef61568a7521d895e7b8470", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10455, "upload_time": "2014-02-18T20:52:49", "url": "https://files.pythonhosted.org/packages/35/ff/8bcb813322c94f7358b79b8a53ad79917782d0c228951ec5d272201b8a11/caches-0.2.13.tar.gz" } ], "0.2.14": [ { "comment_text": "", "digests": { "md5": "a0aa11460746c81502d4e03a8f720929", "sha256": "058ad38b227547f80ae3ff7cefcadd6eed716dc8c2a88f2282c13ffbf34a9a94" }, "downloads": -1, "filename": "caches-0.2.14.tar.gz", "has_sig": false, "md5_digest": "a0aa11460746c81502d4e03a8f720929", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10467, "upload_time": "2014-04-23T02:38:22", "url": "https://files.pythonhosted.org/packages/58/4c/a9901b6c9e8aa7bfcf1e76fae45b2dc91a1293c63570d735e671b9492227/caches-0.2.14.tar.gz" } ], "0.2.15": [ { "comment_text": "", "digests": { "md5": "f7db373570cd3ea5a468c257b504e5ad", "sha256": "3abd44eda3ed82074380397c1e8fa9c3b32d51e3dced0835561392cf95f50e4c" }, "downloads": -1, "filename": "caches-0.2.15.tar.gz", "has_sig": false, "md5_digest": "f7db373570cd3ea5a468c257b504e5ad", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10536, "upload_time": "2014-09-25T08:44:34", "url": "https://files.pythonhosted.org/packages/14/e0/df67e9879e6bae822aa867f08042936e2afdd385d146f21026b0933b694e/caches-0.2.15.tar.gz" } ], "0.2.16": [ { "comment_text": "", "digests": { "md5": "5794213b1a90d882cf8cc67229e1a66d", "sha256": "2b2b88d28dec540396cfecefb3c9bc307d7a0c88f02cc7408fa306d2f36db290" }, "downloads": -1, "filename": "caches-0.2.16.tar.gz", "has_sig": false, "md5_digest": "5794213b1a90d882cf8cc67229e1a66d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10556, "upload_time": "2014-10-06T23:25:28", "url": "https://files.pythonhosted.org/packages/d1/56/f4d9c26a6ad8c0d57d793ba7aba1e374af1da4f55841e3667caaddb5c5a2/caches-0.2.16.tar.gz" } ], "0.2.17": [ { "comment_text": "", "digests": { "md5": "8e90fe1c1b1a9e32b5a6b2a25226edab", "sha256": "d8c78da71d0037f422e19b502179ed3e9b89ac0e59ea9847838a084c9fca6642" }, "downloads": -1, "filename": "caches-0.2.17.tar.gz", "has_sig": false, "md5_digest": "8e90fe1c1b1a9e32b5a6b2a25226edab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10778, "upload_time": "2014-12-23T01:23:49", "url": "https://files.pythonhosted.org/packages/ba/01/ae0b664a840acfd0f37b895dce4951426b1796a52759edcf3dac8b02ec40/caches-0.2.17.tar.gz" } ], "0.2.18": [ { "comment_text": "", "digests": { "md5": "3733cc2dbde21c54631ee0f3b45748ab", "sha256": "8ffd1f6373b48066545cc53c5d60326d3a35c3bf8284b824a1aeb22f50af82ca" }, "downloads": -1, "filename": "caches-0.2.18.tar.gz", "has_sig": false, "md5_digest": "3733cc2dbde21c54631ee0f3b45748ab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10776, "upload_time": "2014-12-23T01:42:17", "url": "https://files.pythonhosted.org/packages/86/61/faa9e89df14990d009f404e424a79d58f9ae5cc947085281e730d5ed5a9e/caches-0.2.18.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "08c545bff735f82c788dc74ce9aa3420", "sha256": "23985609b2840eace74cd509d97ed5308a3278130469ba0f1125e2e6a54cd8e1" }, "downloads": -1, "filename": "caches-0.2.3.tar.gz", "has_sig": false, "md5_digest": "08c545bff735f82c788dc74ce9aa3420", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8909, "upload_time": "2013-10-16T23:48:29", "url": "https://files.pythonhosted.org/packages/93/37/b94da200ba03c50cbe49b57c1aa381cadb2c246ecce1fb2c3f76d8658bfb/caches-0.2.3.tar.gz" } ], "0.2.9": [ { "comment_text": "", "digests": { "md5": "7a5901ff20815afc55c0671e550c1b72", "sha256": "e95c63e3808c1e3eea96f483b3865596467b5f5208cf246032168fc89cac9cef" }, "downloads": -1, "filename": "caches-0.2.9.tar.gz", "has_sig": false, "md5_digest": "7a5901ff20815afc55c0671e550c1b72", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10143, "upload_time": "2013-12-04T04:48:34", "url": "https://files.pythonhosted.org/packages/a8/33/053a0c52c8d492129641b8a451837cb8d147ca8ab7a67993bb48e3a9be6e/caches-0.2.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3733cc2dbde21c54631ee0f3b45748ab", "sha256": "8ffd1f6373b48066545cc53c5d60326d3a35c3bf8284b824a1aeb22f50af82ca" }, "downloads": -1, "filename": "caches-0.2.18.tar.gz", "has_sig": false, "md5_digest": "3733cc2dbde21c54631ee0f3b45748ab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10776, "upload_time": "2014-12-23T01:42:17", "url": "https://files.pythonhosted.org/packages/86/61/faa9e89df14990d009f404e424a79d58f9ae5cc947085281e730d5ed5a9e/caches-0.2.18.tar.gz" } ] }