Skip to content

disk_cache_data decorator - to cache data from external source locally on disk with specified ttl

License

Notifications You must be signed in to change notification settings

mysiar-org/disk_cache_data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

disk_cache_data decorator

Fully configurable decorator with functionnality as Streamlit st.cache_data with local disk storage as backend.

Installation

pip install mysiar-disk-cache-data

Usage

disk_cache_data

Configuration by environment variables:

  • DISK_CACHE_DISABLED=1 - disable caching
  • DISK_CACHE_DEBUG=1 - enable debug logging (currently by print statements)
  • DISK_CACHE_DIR=/path/to/cache/dir - set custom cache directory (default is /tmp/disk_cache)
  • DISK_CACHE_NAMESPACE - subfolder for namespacing (default is disk_cache)
from mysiar.disk_cache_data import disk_cache_data

@disk_cache_data(ttl="30s")
def load_data(a, b):
    return a + b

# first call is whole function process
result = load_data(1, 2)
# each next call within ttl is cached
result = load_data(1, 2)

disk_cache_cleanup

Function to cleanup expired cache files.

from mysiar.disk_cache_data import disk_cache_cleanup
disk_cache_cleanup()

About

disk_cache_data decorator - to cache data from external source locally on disk with specified ttl

Resources

License

Stars

Watchers

Forks

Packages

No packages published