Skip to content

BiocPy/pyBiocFileCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8101ed8 · Mar 23, 2025

History

42 Commits
Mar 23, 2025
Dec 20, 2024
Mar 22, 2025
Mar 22, 2025
Oct 5, 2021
Dec 20, 2024
Mar 22, 2025
Oct 4, 2021
May 23, 2024
Mar 22, 2025
Oct 5, 2021
Nov 22, 2022
Mar 22, 2025
Dec 20, 2024
Mar 22, 2025
May 5, 2024
Oct 4, 2021

Repository files navigation

Project generated with PyScaffold PyPI-Server Unit 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

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 pybiocfilecache import BiocFileCache, CacheConfig
from datetime import timedelta
from pathlib import Path

# 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

# Add file with tags and expiration
from datetime import datetime, timedelta

resource = cache.add(
    "myfile",
    "path/to/file.txt",
    tags=["data", "raw"],
    expires=datetime.now() + timedelta(days=30)
)

# List resources by tag
resources = cache.list_resources(tag="data")

# Search resources
results = cache.search("myfile", field="rname")

# Update resource
cache.update("myfile", "path/to/new_file.txt")

# Remove resource
cache.remove("myfile")

Cache Statistics and Maintenance

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

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

# Purge entire cache
cache.purge()