Skip to main content

memcache memoization decorators and utils for python

Project description

About

memorised is a python module containing handy python-memcached decorators and utils. Specifically the memorise decorator allows you to quickly and simply add memcache caching to any function or method.

Installation

Install memorised using pip:

pip install memorised

Or using the supplied setup.py:

python setup.py install

Usage

To cache a simple unbound function, just include the @memorise() tag to the function definition (the paranthesis are needed as the decorator needs to be initialised at the time of binding to handle memorise specific arguements):

from memorised.decorators import memorise

@memorise()
def myfunction():
    return 'hello world'

You can do the same for simple instance and class methods, however for most instance methods, e.g. when caching results for database models, you probably want to include some form of identity to single out a method call on one instance from another instance. You can do this by providing a list of one ore more parent keys, these are the names of attributes in the parent instance that you want to be appended to the memcache key:

class MyModel:
    id = 1

    @memorise(parent_keys=['id'])
    def get_stats():
        return blah()

For other usage examples see the unittests in tests.py.

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

memorised-1.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

memorised-1.1.0.linux-x86_64.tar.gz (9.8 kB view details)

Uploaded Source

File details

Details for the file memorised-1.1.0.tar.gz.

File metadata

  • Download URL: memorised-1.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for memorised-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a2cb90e04e614a7002f6948d9e54fa3641d2dc5fa70391c128d0df361cc03ce8
MD5 f76e1e13a0c4eb73f3c3114334d08fd8
BLAKE2b-256 c9763befd53117486bedc3ef92bb451a58cf893596254623e33827600c77ddaf

See more details on using hashes here.

File details

Details for the file memorised-1.1.0.linux-x86_64.tar.gz.

File metadata

File hashes

Hashes for memorised-1.1.0.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 a1f41121b61214003829f60742c6c1a692aa2267669cdff00378add2a616cfc4
MD5 2307c766e83726c3c6ac2a61190ef979
BLAKE2b-256 78f51ee3b726bfb31b4037146fe27cffd5b0d66e2df5a0732a63cf53f9023902

See more details on using hashes here.

Supported by

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