ketting
Version:
Opinionated HATEOAS / Rest client.
60 lines • 1.49 kB
JavaScript
/**
* The 'Forever' cache stores any State for as long as the application
* lives.
*
* It is a good default for most applications, but it means that if
* a resource was changed server-side, Ketting will not pick up that change
* until something was done to expire caches.
*
* Executing an unsafe method, calling clearCache() on a resource, or
* when a resource appears in Location, Content-Location, or "invalidates"
* link relationships.
*/
export class ForeverCache {
cache;
constructor() {
this.cache = new Map();
}
/**
* Store a State object.
*
* This function will clone the state object before storing
*/
store(state) {
this.cache.set(state.uri, state.clone());
}
/**
* Retrieve a State object from the cache by its absolute uri
*/
get(uri) {
const state = this.cache.get(uri);
if (!state) {
return null;
}
return state.clone();
}
/**
* Return true if a State object with the specified uri exists in the cache
*/
has(uri) {
return this.cache.has(uri);
}
/**
* Delete a State object from the cache, by its uri
*/
delete(uri) {
this.cache.delete(uri);
}
/**
* Purge the entire cache
*/
clear() {
this.cache.clear();
}
/**
* Clean up any dangling references to avoid memory leaks.
*/
destroy() {
}
}
//# sourceMappingURL=forever.js.map