UNPKG

@thisisagile/easy

Version:

Straightforward library for building domain-driven microservice architectures

55 lines (54 loc) 2.22 kB
import { cacheAge, isCacheAge } from "../chunk-4GK27OOO.mjs"; import "../chunk-HIM2UTGC.mjs"; import { entries, ifDefined } from "../chunk-AVHYDITZ.mjs"; import "../chunk-EBIF6AMC.mjs"; import "../chunk-KCY4RPFR.mjs"; import "../chunk-SSROJBD5.mjs"; import "../chunk-S3NSPQ7M.mjs"; import "../chunk-NNA77YYC.mjs"; import "../chunk-SJGQU3OG.mjs"; import "../chunk-D5IYAIMK.mjs"; import { on } from "../chunk-PF7HDF6B.mjs"; import "../chunk-IXK47WKF.mjs"; import "../chunk-PIRWVOO2.mjs"; import "../chunk-AAND4MKF.mjs"; import "../chunk-4N72FQFX.mjs"; // src/http/CacheControl.ts var CacheControl = class _CacheControl { constructor(enabled = true, directives = {}) { this.enabled = enabled; this.directives = directives; } name = "Cache-Control"; static disabled = () => new _CacheControl(false); static OneSecond = () => new _CacheControl().maxAge(1).staleWhileRevalidate(1); static fiveSeconds = () => new _CacheControl().maxAge(5).staleWhileRevalidate(5); static tenSeconds = () => new _CacheControl().maxAge(10).staleWhileRevalidate(10); static thirtySeconds = () => new _CacheControl().maxAge(30).staleWhileRevalidate(30); static sixtySeconds = () => new _CacheControl().maxAge(60).staleWhileRevalidate(60); static custom = (maxAge, staleWhileRevalidate) => new _CacheControl().maxAge(maxAge).staleWhileRevalidate(staleWhileRevalidate); maxAge = (ca) => on(this, (t) => t.directives["max-age"] = ca); sharedMaxAge = (ca) => on(this, (t) => t.directives["s-maxage"] = ca); noCache = (a) => on(this, (t) => t.directives["no-cache"] = a); mustRevalidate = (a) => on(this, (t) => t.directives["must-revalidate"] = a); private = (a) => on(this, (t) => t.directives["private"] = a); public = (a) => on(this, (t) => t.directives["public"] = a); immutable = (a) => on(this, (t) => t.directives["immutable"] = a); staleWhileRevalidate = (ca) => on(this, (t) => t.directives["stale-while-revalidate"] = ca); value = () => this.toString(); toString() { return entries(this.directives).mapDefined(([k, v]) => ifDefined(v, isCacheAge(v) ? `${k}=${cacheAge.toSeconds(v)}` : k)).join(","); } }; export { CacheControl }; //# sourceMappingURL=CacheControl.mjs.map