atmb4u
cashier
Python

Persistent caching for python functions

Last updated Jul 14, 2025
88
Stars
9
Forks
9
Issues
0
Stars/day
Attention Score
3
Language breakdown
No language data available.
โ–ธ Files click to expand
README

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 -

install cashier

Or you can clone the source and run setup.py

git clone git@github.com: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
  • retryifblank : False

Advanced Usage -

from cashier import cache

@cache(cachefile="sample.db", cachetime=7200, cache_length=1000, retryifblank=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)

retryifblank : 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)

ยฉ 2026 GitRepoTrend ยท atmb4u/cashier ยท Updated daily from GitHub