MCPcopy Create free account
hub / github.com/idosal/git-mcp / setInCache

Function setInCache

src/api/utils/cache.ts:89–108  ·  view source on GitHub ↗

* Store a value in KV cache * @param key - The cache key * @param value - The value to cache * @param ttl - Time to live in seconds (optional, defaults to 12 hours with jitter) * @param env - Environment with Cloudflare bindings

(
  key: string,
  value: any,
  env: Env,
  ttl?: number,
)

Source from the content-addressed store, hash-verified

87 * @param env - Environment with Cloudflare bindings
88 */
89async function setInCache(
90 key: string,
91 value: any,
92 env: Env,
93 ttl?: number,
94): Promise<void> {
95 // Use provided TTL or generate one with jitter
96 const cacheTTL = ttl || getCacheTTL();
97
98 // Store in KV cache
99 if (env?.CACHE_KV) {
100 try {
101 await env.CACHE_KV.put(key, JSON.stringify(value), {
102 expirationTtl: cacheTTL,
103 });
104 } catch (error) {
105 console.warn("Failed to save to Cloudflare KV:", error);
106 }
107 }
108}
109
110/**
111 * Get cached file path for a repository file

Callers 4

cacheFilePathFunction · 0.85
cacheRobotsTxtFunction · 0.85
cacheIsIndexedFunction · 0.85
cacheFetchDocResultFunction · 0.85

Calls 3

getCacheTTLFunction · 0.85
warnMethod · 0.80
putMethod · 0.65

Tested by

no test coverage detected