MCPcopy Create free account
hub / github.com/Pimzino/claude-code-spec-workflow / getCachedFileContent

Function getCachedFileContent

src/file-cache.ts:26–65  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

24 * @returns File content or null if file doesn't exist
25 */
26export function getCachedFileContent(filePath: string): string | null {
27 try {
28 // Normalize the path for cross-platform compatibility
29 const normalizedPath = path.resolve(filePath);
30
31 // Check if file exists
32 if (!existsSync(normalizedPath)) {
33 return null;
34 }
35
36 // Check cache first
37 const now = Date.now();
38 const cached = globalFileCache.get(normalizedPath);
39
40 if (cached) {
41 // Check if cache is still valid (TTL and file modification time)
42 const stats = statSync(normalizedPath);
43 const fileModTime = stats.mtime.getTime();
44
45 if (now - cached.timestamp < CACHE_TTL && cached.mtime === fileModTime) {
46 return cached.content;
47 }
48 }
49
50 // Read file and update cache
51 const content = readFileSync(normalizedPath, 'utf-8');
52 const stats = statSync(normalizedPath);
53
54 globalFileCache.set(normalizedPath, {
55 content,
56 mtime: stats.mtime.getTime(),
57 timestamp: now
58 });
59
60 return content;
61
62 } catch (error) {
63 return null;
64 }
65}
66
67/**
68 * Check if a file exists (with caching for stat calls)

Callers 7

getSpecContextFunction · 0.90
getTasksFunction · 0.90
loadSteeringContextFunction · 0.90
loadSpecContextFunction · 0.90
getTemplateContextFunction · 0.90
getSteeringContextFunction · 0.90
getFileContentFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected