mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
25 lines
597 B
TypeScript
25 lines
597 B
TypeScript
import { AxiosCacheInstance, CacheProperties } from '../axios';
|
|
|
|
export async function updateCache(
|
|
axios: AxiosCacheInstance,
|
|
data: any,
|
|
entries: CacheProperties['update']
|
|
) {
|
|
for (const [cacheKey, value] of Object.entries(entries)) {
|
|
if (value == 'delete') {
|
|
await axios.storage.remove(cacheKey);
|
|
continue;
|
|
}
|
|
|
|
const oldValue = await axios.storage.get(cacheKey);
|
|
const newValue = value(oldValue, data);
|
|
|
|
if (newValue === undefined) {
|
|
await axios.storage.remove(cacheKey);
|
|
continue;
|
|
}
|
|
|
|
await axios.storage.set(cacheKey, newValue);
|
|
}
|
|
}
|