Cache management API - simple interface list() to see what's cached, get(key) to retrieve by name
- Source:
Methods
(static) checkCache(options) → {Promise.<(Object|null)>}
Check if data is available in cache without fetching Returns metadata about cached data including size and age
Parameters:
| Name | Type | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Check options Properties
|
- Source:
Returns:
Cached data info or null if not cached
- Type
- Promise.<(Object|null)>
Example
// Check if NLDAS data is cached
const cached = await hydro.data.cache.checkCache({
params: { source: 'nldas', datatype: 'hourly' },
args: { lat: 40, lon: -105, startDate: '2024-01-01', endDate: '2024-01-02' }
});
if (cached) {
console.log(`Data cached: ${cached.sizeMB} MB, ${cached.ageDays} days old`);
}
(static) clear() → {Promise.<boolean>}
Clear all cache
- Source:
Returns:
Success
- Type
- Promise.<boolean>
Example
await hydro.data.cache.clear();
(static) delete(cacheKey) → {Promise.<boolean>}
Delete cached dataset by key
Parameters:
| Name | Type | Description |
|---|---|---|
cacheKey |
string | Key to delete |
- Source:
Returns:
Success
- Type
- Promise.<boolean>
Example
await hydro.data.cache.delete('nldas_hourly_lat40.0_lon-105.0_start2024-01-01');
(static) getStats() → {Promise.<Object>}
Get comprehensive cache statistics Returns total size, file count, and detailed entries
- Source:
Returns:
Cache statistics
- Type
- Promise.<Object>
Example
const stats = await hydro.data.cache.getStats();
console.log(`Total cache size: ${stats.totalSizeMB} MB`);
console.log(`Files cached: ${stats.totalFiles}`);
(static) list(optionsopt) → {Promise.<Array>}
List all cached datasets with human-readable key names
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Optional filter options Properties
|
- Source:
Returns:
Array with cacheKey, size, age for each cached dataset
- Type
- Promise.<Array>
Example
const cached = await hydro.data.cache.list();
cached.forEach(item => {
console.log(`${item.cacheKey} - ${item.sizeFormatted}, ${item.ageFormatted} old`);
});