UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

25 lines (24 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCacheControl = getCacheControl; const helpers_js_1 = require("../../../../shared/page-configs/helpers.js"); const getConfigValueRuntime_js_1 = require("../../../../shared/page-configs/getConfigValueRuntime.js"); const defaultValue = 'no-store, max-age=0'; function getCacheControl(pageId, pageConfigs, statusCode) { // TODO/v1-release: remove if (pageConfigs.length === 0) return defaultValue; if (statusCode > 499) return defaultValue; if (pageId) { const pageConfig = (0, helpers_js_1.getPageConfig)(pageId, pageConfigs); const configValue = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'cacheControl', 'string'); const value = configValue?.value; if (value) return value; } // - Disabling caching by default is the safest strategy, because caching is problematic with authentication as described in https://github.com/vikejs/vike/issues/1275#issuecomment-1824366875 // - Are there use cases when we don't need to disable caching? // - When there isn't any <script id="vike_pageContext" type="application/json"> then we can safely have caching. (We don't implement this exception because we're lazy and it's quite a rare situation.) return defaultValue; }