Name | ring JSON |
Version |
0.10.1
JSON |
| download |
home_page | https://github.com/youknowone/ring |
Summary | Function-oriented cache interface with built-in memcache & redis + asyncio support. |
upload_time | 2023-03-30 04:59:25 |
maintainer | |
docs_url | None |
author | Jeong YunWon |
requires_python | |
license | |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
Ring
====
.. image:: https://badges.gitter.im/ring-cache/community.svg
:alt: Join the chat at https://gitter.im/ring-cache/community
:target: https://gitter.im/ring-cache/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
.. image:: https://github.com/youknowone/ring/actions/workflows/python-package.yml/badge.svg
.. image:: https://codecov.io/gh/youknowone/ring/graph/badge.svg
:target: https://codecov.io/gh/youknowone/ring
Let's concentrate on code, not on storages.
Ring shows a way to control cache in point of view of code - not about storages.
Ring's decorator is convenient but also keeps fluency for general scenarios.
asyncio support for Python3.5+!
Take advantage of perfectly explicit and fully automated cache interface.
Ring decorators convert your functions to cached version of them, with extra
control methods.
Documentation
-------------
Full documentation with examples and references:
`<http://ring-cache.readthedocs.io/>`_
- Function/method support.
- asyncio support.
- Django support.
- Bulk access support.
Function cache
--------------
.. code:: python
import ring
import memcache
import requests
mc = memcache.Client(['127.0.0.1:11211'])
# working for mc, expire in 60sec
@ring.memcache(mc, time=60)
def get_url(url):
return requests.get(url).content
# normal way - it is cached
data = get_url('http://example.com')
It is a normal smart cache flow.
But ring is different when you want to explicitly control it.
.. code:: python
# delete the cache
get_url.delete('http://example.com')
# get cached data or None
data_or_none = get_url.get('http://example.com')
# get internal cache key
key = get_url.key('http://example.com')
# and access directly to the backend
direct_data = mc.get(key)
Method cache
------------
.. code:: python
import ring
import redis
rc = redis.StrictRedis()
class User(dict):
def __ring_key__(self):
return self['id']
# working for rc, no expiration
# using json coder for non-bytes cache data
@ring.redis(rc, coder='json')
def data(self):
return self.copy()
# parameters are also ok!
@ring.redis(rc, coder='json')
def child(self, child_id):
return {'user_id': self['id'], 'child_id': child_id}
user = User(id=42, name='Ring')
# create and get cache
user_data = user.data() # cached
user['name'] = 'Ding'
# still cached
cached_data = user.data()
assert user_data == cached_data
# refresh
updated_data = user.data.update()
assert user_data != updated_data
# id is the cache key so...
user2 = User(id=42)
# still hitting the same cache
assert updated_data == user2.data()
Installation
------------
PyPI is the recommended way.
.. sourcecode:: shell
$ pip install ring
To browse versions and tarballs, visit:
`<https://pypi.python.org/pypi/ring/>`_
To use memcached or redis, don't forget to install related libraries.
For example: python-memcached, python3-memcached, pylibmc, redis-py, Django etc
It may require to install and run related services on your system too.
Look for `memcached` and `redis` for your system.
Contributors
------------
See contributors list on:
`<https://github.com/youknowone/ring/graphs/contributors>`_
Raw data
{
"_id": null,
"home_page": "https://github.com/youknowone/ring",
"name": "ring",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Jeong YunWon",
"author_email": "ring@youknowone.org",
"download_url": "https://files.pythonhosted.org/packages/50/77/863775e66d19f32f0264cd4e806c6247c9907d544ccca350b8b0e18ed412/ring-0.10.1.tar.gz",
"platform": null,
"description": "Ring\n====\n\n.. image:: https://badges.gitter.im/ring-cache/community.svg\n :alt: Join the chat at https://gitter.im/ring-cache/community\n :target: https://gitter.im/ring-cache/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge\n\n.. image:: https://github.com/youknowone/ring/actions/workflows/python-package.yml/badge.svg\n.. image:: https://codecov.io/gh/youknowone/ring/graph/badge.svg\n :target: https://codecov.io/gh/youknowone/ring\n\nLet's concentrate on code, not on storages.\n\nRing shows a way to control cache in point of view of code - not about storages.\nRing's decorator is convenient but also keeps fluency for general scenarios.\n\nasyncio support for Python3.5+!\n\nTake advantage of perfectly explicit and fully automated cache interface.\nRing decorators convert your functions to cached version of them, with extra\ncontrol methods.\n\n\nDocumentation\n-------------\n\nFull documentation with examples and references:\n`<http://ring-cache.readthedocs.io/>`_\n\n- Function/method support.\n- asyncio support.\n- Django support.\n- Bulk access support.\n\n\nFunction cache\n--------------\n\n.. code:: python\n\n import ring\n import memcache\n import requests\n\n mc = memcache.Client(['127.0.0.1:11211'])\n\n # working for mc, expire in 60sec\n @ring.memcache(mc, time=60)\n def get_url(url):\n return requests.get(url).content\n\n # normal way - it is cached\n data = get_url('http://example.com')\n\nIt is a normal smart cache flow.\n\nBut ring is different when you want to explicitly control it.\n\n\n.. code:: python\n\n # delete the cache\n get_url.delete('http://example.com')\n # get cached data or None\n data_or_none = get_url.get('http://example.com')\n\n # get internal cache key\n key = get_url.key('http://example.com')\n # and access directly to the backend\n direct_data = mc.get(key)\n\n\nMethod cache\n------------\n\n.. code:: python\n\n import ring\n import redis\n\n rc = redis.StrictRedis()\n\n class User(dict):\n def __ring_key__(self):\n return self['id']\n\n # working for rc, no expiration\n # using json coder for non-bytes cache data\n @ring.redis(rc, coder='json')\n def data(self):\n return self.copy()\n\n # parameters are also ok!\n @ring.redis(rc, coder='json')\n def child(self, child_id):\n return {'user_id': self['id'], 'child_id': child_id}\n\n user = User(id=42, name='Ring')\n\n # create and get cache\n user_data = user.data() # cached\n user['name'] = 'Ding'\n # still cached\n cached_data = user.data()\n assert user_data == cached_data\n # refresh\n updated_data = user.data.update()\n assert user_data != updated_data\n\n # id is the cache key so...\n user2 = User(id=42)\n # still hitting the same cache\n assert updated_data == user2.data()\n\n\nInstallation\n------------\n\nPyPI is the recommended way.\n\n.. sourcecode:: shell\n\n $ pip install ring\n\nTo browse versions and tarballs, visit:\n `<https://pypi.python.org/pypi/ring/>`_\n\n\nTo use memcached or redis, don't forget to install related libraries.\nFor example: python-memcached, python3-memcached, pylibmc, redis-py, Django etc\n\nIt may require to install and run related services on your system too.\nLook for `memcached` and `redis` for your system.\n\n\nContributors\n------------\n\nSee contributors list on:\n `<https://github.com/youknowone/ring/graphs/contributors>`_\n",
"bugtrack_url": null,
"license": "",
"summary": "Function-oriented cache interface with built-in memcache & redis + asyncio support.",
"version": "0.10.1",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5077863775e66d19f32f0264cd4e806c6247c9907d544ccca350b8b0e18ed412",
"md5": "60549d0ca4329e8ab72ead6fcad5972b",
"sha256": "5959e867978f29ad3399b011e7c7b5116fdf60fad9e63881df66e890cdbe329c"
},
"downloads": -1,
"filename": "ring-0.10.1.tar.gz",
"has_sig": false,
"md5_digest": "60549d0ca4329e8ab72ead6fcad5972b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 33820,
"upload_time": "2023-03-30T04:59:25",
"upload_time_iso_8601": "2023-03-30T04:59:25.823699Z",
"url": "https://files.pythonhosted.org/packages/50/77/863775e66d19f32f0264cd4e806c6247c9907d544ccca350b8b0e18ed412/ring-0.10.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-30 04:59:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "youknowone",
"github_project": "ring",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "ring"
}