frescas
Self-refreshable in-memory data cache.
FreshValue
and AsyncFreshValue
- single refreshable value.FreshValueMap
and AsyncFreshValueMap
- maps of refreshable values.
Usage example:
const currentAccessToken = new AsyncFreshValue({
refreshPeriodMillis: 0,
load: async (settings) => {
const response = await fetchAccessToken();
settings.refreshPeriodMillis = Date.now() - response.expirationTime;
return response.token;
}
});
async function getA(): A {
const accessToken: string = await currentAccessToken.get();
return fetch(accessToken, );
}
async function getB(): B {
const accessToken: string = await currentAccessToken.get();
return fetch(accessToken, );
}
Docs & tests
Check in-code documentation and tests: