Skip to main content

Cache Decorator

https://travis-ci.org/jealous/cachez.svg https://coveralls.io/repos/jealous/cachez/badge.svg https://img.shields.io/pypi/v/cachez.svg

VERSION: 0.1.2

Introduction

Function decorator that helps to cache/memoize the result of a function/method.

This package contains following decorators.

  • cache: cache the result of the function globally.

  • instance_cache: cache the result of a method in the instance (self)

  • clear_instance_cache: clear the method results cached on the instance.

And one function.

  • clear_cache: clear the global function cache.

Tested on python 2.7 and python 3.4.

For quick start, check the tutorial section of this page. Check cachez_test.py for detail examples.

Installation

pip install cachez

License

Apache License version 2

Tutorial

  • To cache the result of the a function globally, decorate the function with cache.

@cache
def foo(x, y):
    ...
  • To clear the global cache, call clear_cache().

clear_cache()
  • To cache the result of the method in the instance, decorate the method with instance_cache. To clear the method cache on the instance, decorate your clear method with clear_instance_cache.

class Foo(object):
    @instance_cache
    def bar(a, b):
        ...

    @clear_instance_cache
    def clear():
        ...
  • To persist the function return value, use persisted decorator. This decorator takes input parameter which specify when the cache will expire. The default value for cache expiration is set to 1 day.

class Foo(object):
    @persisted()
    def default_persist_for_1_day(x):
        ...

    @persisted(seconds=5)
    def persist_return_value_for_5_seconds(y):
        ...
  • The default persist folder is set to ~/.cachez. You could customize it by calling set_persist_folder.

To file issue, please visit:

https://github.com/jealous/cachez

Contact author:

Contributors:

Metadata

Release files for cachez 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cachez 0.1.2
File Size Uploaded Provenance Actions
cachez-0.1.2.tar.gz 11.2 kB Without provenance Details for cachez-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cachez 0.1.2
File Interpreter ABI Platform Actions
cachez-0.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details for cachez-0.1.2-py2.py3-none-any.whl

Total release size: 19.6 kB

Release files / cachez-0.1.2.tar.gz

Download URL cachez-0.1.2.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3ebc0b052d56755902b8068a4ed0d642325f96b0070862288abaad77c9d3c282
BLAKE2b-256 checksum
How to use checksums
c53e67c7ce94d258cf0070f62aed6ef705ce83314e7e72eb40d881b5cc90642a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cachez-0.1.2-py2.py3-none-any.whl

Download URL cachez-0.1.2-py2.py3-none-any.whl
Size 8.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0322d0032d6ed02b83b64a947ee10c7848e98261af5f9d7846a89e6abdc49b22
BLAKE2b-256 checksum
How to use checksums
4ce73ebd5990d7d2140a138f70ce2ff5bfdc9f813ba545fbd0cd9a6857940784
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for cachez 0.1.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page