MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / shouldCache

Function shouldCache

packages/redis/cachable.ts:116–138  ·  view source on GitHub ↗
(result: unknown, options: CacheableOptions = {})

Source from the content-addressed store, hash-verified

114}
115
116function shouldCache(result: unknown, options: CacheableOptions = {}): boolean {
117 // Don't cache undefined or null
118 if (result === undefined || result === null) {
119 return false;
120 }
121
122 // Don't cache empty strings
123 if (typeof result === 'string') {
124 return result.length > 0;
125 }
126
127 if (Array.isArray(result)) {
128 return options.cacheEmptyArray ? true : result.length > 0;
129 }
130
131 // Don't cache empty objects
132 if (typeof result === 'object' && result !== null) {
133 return Object.keys(result).length > 0;
134 }
135
136 // Cache everything else (booleans, numbers, etc.)
137 return true;
138}
139
140const DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.*Z$/;
141const parseCache = (cached: string) => {

Callers 2

cachedFnFunction · 0.85
cacheableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected