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
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.
# 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
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.
$ pip install ring
- To browse versions and tarballs, visit:
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:
Metadata
Release files for ring 0.10.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ring-0.10.1.tar.gz | 33.8 kB | Without provenance | Details for ring-0.10.1.tar.gz |
Release files / ring-0.10.1.tar.gz
| Download URL | ring-0.10.1.tar.gz |
|---|---|
| Size | 33.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5959e867978f29ad3399b011e7c7b5116fdf60fad9e63881df66e890cdbe329c
|
|
BLAKE2b-256 checksum How to use checksums |
5077863775e66d19f32f0264cd4e806c6247c9907d544ccca350b8b0e18ed412
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for ring 0.10.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.