Giter VIP home page Giter VIP logo

cashier's Introduction

Cashier

Persistent caching for python functions

Simply add a decorator to a python function and cache the results for future use. Extremely handy when you are dealing with I/O heavy operations which seldom changes or CPU intensive functions as well.

Anatomically, once a function is called, result from the function is cached into an SQLite3 database locally, with an expiry time. There is a maximum length for the cache to prevent cache flooding the file system.

Installation

pip install cashier

Or you can clone the source and run setup.py

git clone [email protected]:atmb4u/cashier.git
cd cashier
python setup.py install

Usage

from cashier import cache

@cache()
def complex_function(a,b,c,d):
    return complex_calculation(a,b,c,d)

If you go ahead on the above configuration, following are the default values

  • cache_file : .cache

  • cache_time : 84600

  • cache_length : 10000

  • retry_if_blank : False

Advanced Usage

from cashier import cache

@cache(cache_file="sample.db", cache_time=7200, cache_length=1000, 
       retry_if_blank=True)
def complex_function(a, b, c, d):
    return complex_calculation(a, b, c, d)

cache_file : SQLite3 file name to which cached data should be written into (defaults to .cache)

cache_time : how long should the data be cached in seconds (defaults to 1 day)

cache_length : how many different arguments and corresponding data should be cached (defaults to 10000)

retry_if_blank : If True, will retry for the data if blank data is cached ( default is False)

Performance Benchmark

For reproducing results, run python test.py from the project root.

No Cache Run: 9.932126 seconds

First Caching Run: 9.484081 seconds

Cached Run: 0.606016 seconds (16 x faster)

cashier's People

Contributors

atmb4u avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

cashier's Issues

add location of pickle data

It would be nice to be able to specify the cache file locations (~/.cachier) - as this may not be the wanted location.

Support for SQLite 'in memory' mode

Sorry if this is already supported, but it wasn't clear from the docs or the tests, if this library supports using the sqlite in memory operation mode to avoid unnecessary file system access if you don't need a persistent cache across process restarts.

feature request: profiler/stats on cache usage

Would be great to be able to run a report that would show how many times each cache was hit, how many were hits or missed, and how long it took to complete the non-cached calls. This would help tune how cachier is configured.

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.