Skip to content

About

Python implementation of the BiocFileCache R package

Topics

Resources

Contributing

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

PyPI-Server Unit tests R and Python Interop

pyBiocFileCache

pyBiocFileCache is a Python package that provides a file caching system with resource validation, expiration management, and SQLite-backed metadata. Compatible with the BiocFileCache R package.

Installation

Install from PyPI:

pip install pybiocfilecache

Quick Start

from pybiocfilecache import BiocFileCache

# Initialize cache
cache = BiocFileCache("path/to/cache/directory")

# Add a file to cache
resource = cache.add("myfile", "path/to/file.txt")

# Retrieve a file from cache
resource = cache.get("myfile")

# Use the cached file
print(resource["rpath"])  # Path to cached file

Advanced Usage

Configuration

from datetime import timedelta
from pathlib import Path

from pybiocfilecache import BiocFileCache, CacheConfig

# Create custom configuration
config = CacheConfig(
    cache_dir=Path("cache_directory"),
    cleanup_interval=timedelta(days=7),
)

# Initialize cache with configuration
cache = BiocFileCache(config=config)

Resource Management

from datetime import datetime, timedelta, timezone

# Add file with expiration
resource = cache.add(
    "myfile",
    "path/to/file.txt",
    expires=datetime.now(timezone.utc) + timedelta(days=30),
)

# Immediate lookup without waiting on missing files
record = cache.get(rid="BFC1", wait=False)

# List resources
resources = cache.list_resources()

# Search resources (exact or substring match)
results = cache.search("myfile", field="rname")

# Update resource by name or rid
cache.update("myfile", "path/to/new_file.txt")
cache.update(rid="BFC1", fpath="path/to/new_file.txt")

# Remove resource by name or rid
cache.remove("myfile")

Cache Statistics and Maintenance

# Get cache statistics
stats = cache.get_stats()
print(stats)

# Clean up expired resources
removed_count = cache.cleanup()

# Verify integrity of cached files
valid, invalid = cache.verify_cache()

# Purge entire cache
cache.purge()

About

Python implementation of the BiocFileCache R package

Topics

Resources

Contributing

Stars

3 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages