File size: 739 Bytes
35743bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
 * Cache Control Settings
 *
 * Provides cached access to cache control settings for performance.
 * Settings are fetched once and cached to avoid repeated DB hits.
 */

import { getSettings } from "./db/settings";
import type { CacheControlMode } from "@omniroute/open-sse/utils/cacheControlPolicy";

let cachedSettings: CacheControlMode | null = null;

export async function getCacheControlSettings(): Promise<CacheControlMode> {
  if (cachedSettings !== null) {
    return cachedSettings;
  }

  const settings = await getSettings();
  cachedSettings = (settings.alwaysPreserveClientCache as CacheControlMode) || "auto";
  return cachedSettings;
}

export function invalidateCacheControlSettingsCache() {
  cachedSettings = null;
}