k.utils.CDN
Current site CDN switch and cache time
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| KScript API, Page / View server scripts | Site served behind CDN; property name CDN is uppercase | Disabling CDN per response or setting cache duration in minutes |
k.utils.CDN controls CDN behavior in the current request context (attribute name CDN, case-sensitive).
Runtime Behavior Note
In the current runtime, enableCDN() invokes the same underlying disable flag as disableCDN(), so calling enableCDN() does not re-enable CDN caching for the current response.
Quick Start
js
k.api.get("preview", () => {
k.utils.CDN.disableCDN()
return {
draft: k.request.queryString.get("id"),
generatedAt: k.utils.date.formate(k.utils.date.now)
}
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
disableCDN() | Disable CDN caching for the current response | void |
enableCDN() | Enable CDN flag for the current response (see Runtime Behavior Note above) | void |
setCacheTime(minutes) | Set CDN cache duration in minutes | void |
disableCDN() / enableCDN()
Disable or configure the CDN flag for the current response.
Parameters: None.
Returns: void.
| Method | Parameter | Return | Description |
|---|---|---|---|
disableCDN() | None | void | Do not use CDN for the current response |
enableCDN() | None | void | Allow CDN for the current response (see Runtime Behavior Note at top) |
js
k.api.get("preview", () => {
k.utils.CDN.disableCDN()
return {
draft: k.request.queryString.get("id"),
generatedAt: k.utils.date.formate(k.utils.date.now)
}
})setCacheTime()
Set CDN cache minutes.
| Parameter | Type | Required | Description |
|---|---|---|---|
minutes | number | Yes | CDN cache time in minutes |
Returns: void.
js
k.api.get("public-summary", () => {
k.utils.CDN.setCacheTime(15)
return {
title: "Public summary",
cachedForMinutes: 15
}
})TypeScript Definitions
ts
interface CDNUtility {
disableCDN(): void;
enableCDN(): void;
setCacheTime(minutes: number): void;
}