Skip to content

Repository files navigation

Project generated with PyScaffoldPyPI-ServerUnit tests

pyBiocFileCache

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.

Installation

Install from PyPI,

pip install pybiocfilecache

Quick Start

frompybiocfilecacheimportBiocFileCache# 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 file

Advanced Usage

Configuration

frompybiocfilecacheimportBiocFileCache, CacheConfigfromdatetimeimporttimedeltafrompathlibimportPath# Create custom configurationconfig=CacheConfig(
cache_dir=Path("cache_directory"),
cleanup_interval=timedelta(days=7),
)
# Initialize cache with configurationcache=BiocFileCache(config=config)

Resource Management

# 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")

Cache Statistics and Maintenance

# Get cache statisticsstats=cache.get_stats()
print(stats)
# Clean up expired resourcesremoved_count=cache.cleanup()
# Purge entire cachecache.purge()

About

Python implementation of the BiocFileCache R package

Topics

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages