Skip to main content

A fully-featured cache for Python applications.

Project description

Rupee is a simple, but fully-featured caching library for Python 3.

Engines

Rupee supports caching using process memory, Redis, and Memcached.

For Redis support:

pip install redis

For Memcached support, you can use pylibmc:

pip install pylibmc

or python-memcache:

pip install python-memcache

Cache Access

You can create cache instances like this:

memory = rupee.engine.Memory()
memcached = rupee.engine.Memcached(['localhost:11211'])
redis = rupee.engine.Redis('localhost:6379')

All instances conform to the same API, which offer the get/set/delete operations you’d expect:

cache = rupee.engine.Memcached(['localhost:11211'])
cache.set('foo', 'bar', ttl=3600)
cache.set_multi({'baz': 1, 'qux': 2})
cache.get('baz') == 1
cache.get_multi(['foo', 'qux']) == {'foo': 'bar', 'qux': 2}
cache.delete('qux')
cache.delete_all(['foo', 'baz'])
cache.delete_all_data()

Cached Decorators

You can decorate functions to be cache their results:

cache = rupee.engine.Redis('localhost:6379')

@rupee.cached(cache, ttl=3600)
def foo(bar, baz):
    return _some_expensive_thing(bar, baz)

To clear the cache entry for a function call:

foo.dirty(1, 2)

For functions that perform bulk operations, you can use the multi-cache decorator:

@rupee.multi_cached(cache):
def get(items):
    return {item: _some_expensive_thing(item) for item in items}

Functions decorated with multi_cached must take a single list as an argument and return a dictionary keyed on the items in that list. Then, results for each item will be cached separately, and only the needed items will be passed to the function. To illustrate:

get([1, 2, 3]) # calls _some_expensive_thing on 1, 2, and 3
get([1, 2, 3]) # _some_expensive_thing is never called
get([2, 3, 4]) # calls _some_expensive_thing only on 4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rupee-0.0.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rupee-0.0.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file rupee-0.0.1.tar.gz.

File metadata

  • Download URL: rupee-0.0.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rupee-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7ce5f82a883d713650ed38a7fc30f424077732b61dd0eae66919265869aa91a6
MD5 155ff754846832dd0e3bbbbfbccbcb31
BLAKE2b-256 f374655a22c011a8d16d884759dcd84c6e687cc26a09c2b81bb6ba968ce20491

See more details on using hashes here.

File details

Details for the file rupee-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for rupee-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97849f3b53715a44ca6a80e5a65e8df79fa4545969159553eb6246d2cee7466a
MD5 8171e32e91d4d0253bd8c5a1d5fccd42
BLAKE2b-256 a551e3fbccb9251a775b0a3247e7504ee56a88225bc60217d8f2991c255d4a53

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page