varunayan.cache module¶
Caching system for varunayan downloads.
This module provides functions for managing cached climate data downloads to avoid redundant API calls.
- varunayan.cache.get_cache_dir() Path[source]¶
Get the cache directory for varunayan.
Uses platformdirs-style logic to find appropriate cache location: - Linux: ~/.cache/varunayan - macOS: ~/Library/Caches/varunayan - Windows: %LOCALAPPDATA%/varunayan/cache
- Returns:
Path to the cache directory
- varunayan.cache.cache_exists(request_id: str, variables: List[str], start_date: str, end_date: str, frequency: str, source: str = 'era5', **kwargs: Any) bool[source]¶
Check if cached data exists for the given parameters.
- Parameters:
request_id – Original request identifier
variables – List of variables requested
start_date – Start date
end_date – End date
frequency – Temporal frequency
source – Data source (‘era5’ or ‘imd’)
**kwargs – Additional parameters (bounds, resolution, etc.)
- Returns:
True if cache exists, False otherwise
- varunayan.cache.get_cached_data(request_id: str, variables: List[str], start_date: str, end_date: str, frequency: str, source: str = 'era5', **kwargs: Any) DataFrame | None[source]¶
Retrieve cached data if it exists.
- Parameters:
request_id – Original request identifier
variables – List of variables requested
start_date – Start date
end_date – End date
frequency – Temporal frequency
source – Data source (‘era5’ or ‘imd’)
**kwargs – Additional parameters
- Returns:
DataFrame if cache exists, None otherwise
- varunayan.cache.save_to_cache(df: DataFrame, request_id: str, variables: List[str], start_date: str, end_date: str, frequency: str, source: str = 'era5', **kwargs: Any) str[source]¶
Save data to cache.
- Parameters:
df – DataFrame to cache
request_id – Original request identifier
variables – List of variables requested
start_date – Start date
end_date – End date
frequency – Temporal frequency
source – Data source (‘era5’ or ‘imd’)
**kwargs – Additional parameters
- Returns:
Cache key (MD5 hash)
- varunayan.cache.show_cache_info() None[source]¶
Display information about the cache directory and its contents.
- varunayan.cache.list_cache(source: str = 'all') DataFrame[source]¶
List all cached files with metadata.
- Parameters:
source – Filter by source (‘era5’, ‘imd’, or ‘all’)
- Returns:
DataFrame with cache entries
- varunayan.cache.cache_stats() Dict[str, Any][source]¶
Get statistics about the cache.
- Returns:
Dictionary with cache statistics
- varunayan.cache.clear_cache(source: str = 'all', older_than_days: int | None = None, confirm: bool = True) int[source]¶
Clear cached files.
- Parameters:
source – Filter by source (‘era5’, ‘imd’, or ‘all’)
older_than_days – Only delete files older than this many days
confirm – If True, prompt for confirmation before deleting
- Returns:
Number of files deleted