pyBiocFileCache is a Python package that provides a robust file caching system with resource validation, cache size management, file compression, and resource tagging. Compatible with BiocFileCache R package.
Install from PyPI,
pip install pybiocfilecachefrompybiocfilecacheimportBiocFileCache# Initialize cachecache=BiocFileCache("path/to/cache/directory")
# Add a file to cacheresource=cache.add("myfile", "path/to/file.txt")
# Retrieve a file from cacheresource=cache.get("myfile")
# Use the cached fileprint(resource["rpath"]) # Path to cached filefrompybiocfilecacheimportBiocFileCache, CacheConfigfromdatetimeimporttimedeltafrompathlibimportPath# Create custom configurationconfig=CacheConfig(
cache_dir=Path("cache_directory"),
cleanup_interval=timedelta(days=7),
)
# Initialize cache with configurationcache=BiocFileCache(config=config)# Add file with tags and expirationfromdatetimeimportdatetime, timedeltaresource=cache.add(
"myfile",
"path/to/file.txt",
tags=["data", "raw"],
expires=datetime.now() +timedelta(days=30)
)
# List resources by tagresources=cache.list_resources(tag="data")
# Search resourcesresults=cache.search("myfile", field="rname")
# Update resourcecache.update("myfile", "path/to/new_file.txt")
# Remove resourcecache.remove("myfile")# Get cache statisticsstats=cache.get_stats()
print(stats)
# Clean up expired resourcesremoved_count=cache.cleanup()
# Purge entire cachecache.purge()