gardarjuto's picture
major refactor
1d31670
import os
from pathlib import Path
from datetime import timedelta
class CacheConfig:
def __init__(self):
self.base_path = Path(os.getenv("HF_HOME", "."))
self.cache_ttl = timedelta(minutes=5) # 5 minute cache TTL
def get_cache_path(self, cache_type: str = "datasets") -> Path:
"""Get cache path for different cache types"""
cache_path = self.base_path / "cache" / cache_type
cache_path.mkdir(parents=True, exist_ok=True)
return cache_path
def flush_cache(self, cache_type: str = None):
"""Flush specific cache or all caches"""
if cache_type:
cache_path = self.get_cache_path(cache_type)
for file in cache_path.glob("*"):
if file.is_file():
file.unlink()
else:
cache_base = self.base_path / "cache"
if cache_base.exists():
for cache_dir in cache_base.iterdir():
if cache_dir.is_dir():
for file in cache_dir.glob("*"):
if file.is_file():
file.unlink()
# Global cache configuration
cache_config = CacheConfig()