@veracity/vui
Version:
Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.
31 lines (30 loc) • 806 B
JavaScript
//#region src/svg/cache.ts
/**
* Provides svg caching functionality to avoid redundant XHR requests.
* When the retrieved item doesn't exist in cache yet, a request is sent
* to its 'src' url. The request's promise is cached for that 'src' key
* and can be used for the whole session without repeating requests.
*/
var Cache = class {
cache = /* @__PURE__ */ new Map();
add = (src, svg) => {
this.cache.set(src, svg);
};
get = (src) => {
const item = this.cache.get(src);
if (!item) {
const promise = fetch(src).then((res) => res.text());
this.add(src, promise);
return promise;
}
return item;
};
reset = () => {
this.cache.clear();
};
};
const cache = new Cache();
//#endregion
export { cache as default };
globalThis.__vuiVersion__ = "5.3.1"
//# sourceMappingURL=cache.js.map