Giter VIP home page Giter VIP logo

anycache's Introduction

https://img.shields.io/pypi/dm/anycache.svg?label=pypi%20downloads https://readthedocs.org/projects/anycache/badge/?version=latest https://readthedocs.org/projects/anycache/badge/?version=2.1.0 https://img.shields.io/badge/linter-pylint-%231674b1?style=flat https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square

To cache the result of a function, use the global unlimited anycache:

>>> from anycache import anycache
>>> @anycache()
... def myfunc(posarg, kwarg=3):
...     print("  Calcing %r + %r = %r" % (posarg, kwarg, posarg + kwarg))
...     return posarg + kwarg
>>> myfunc(8, 5)
  Calcing 8 + 5 = 13
13
>>> myfunc(8, 5)
13

anycache caches nearly any python object. Also lambda statements. It uses Dill as backend. An improved version of pythons build-in pickle.

To preserve the result between multiple python runs, a persistent cache directory needs to be set.

>>> from anycache import anycache
>>> @anycache(cachedir='/tmp/anycache.my')
... def myfunc(posarg, kwarg=3):
...     return posarg + kwarg

The AnyCache object serves additional functions for cache clearing and size handling.

Installation

To install the anycache module run:

pip install anycache

If you do not have write-permissions to the python installation, try:

pip install anycache --user

anycache's People

Contributors

c0fec0de avatar djakschik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

anycache's Issues

Option for Max Cache Age?

I've been examining anycache today and it looks like the perfect solution to a problem I've been having with a small workflow script of mine. However I noticed there doesn't seem to be a way of controlling the maximum amount of time a cached result can live for. In my script I'd like for it to update the cache after it has lived for a certain amount of time (say, every week).

I did see that there's an is_outdated function, but that seems to be based on the source file returning True whenever the source file has been updated (which makes sense).

Could we get an option to specify maxage alongside maxsize for the cached results of a function? e.g.

import datetime

@anycache(cachedir="/path/to/cache", maxage=datetime.timedelta(weeks=1), maxsize=1000000)
def my_anycached_function():
  ...

Passing in None to the maxage parameter could disable the max age check.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.