MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / NewFileCacheWithSize

Function NewFileCacheWithSize

internal/cache/cache.go:67–90  ·  view source on GitHub ↗

NewFileCacheWithSize creates a new file-based cache with a maximum size limit. When the cache exceeds maxSize items, least recently used items are evicted. maxSize of 0 means unlimited cache size.

(cacheDir string, persisted bool, maxSize int)

Source from the content-addressed store, hash-verified

65// When the cache exceeds maxSize items, least recently used items are evicted.
66// maxSize of 0 means unlimited cache size.
67func NewFileCacheWithSize(cacheDir string, persisted bool, maxSize int) (*FileCache, error) {
68 // Create cache directory if it doesn't exist
69 if err := os.MkdirAll(cacheDir, 0o750); err != nil {
70 return nil, fmt.Errorf("failed to create cache directory: %w", err)
71 }
72
73 cache := &FileCache{
74 dir: cacheDir,
75 inMemory: make(map[string]*list.Element),
76 lruList: list.New(),
77 maxSize: maxSize,
78 persisted: persisted,
79 }
80
81 // If persisted, load existing cache files
82 if persisted {
83 if err := cache.loadCacheFiles(); err != nil {
84 // Non-fatal error, just log it
85 getCacheLogger().Debug("Warning: Failed to load cache files: %v", err)
86 }
87 }
88
89 return cache, nil
90}
91
92// loadCacheFiles loads all existing cache files into memory.
93func (c *FileCache) loadCacheFiles() error {

Callers 1

NewFileCacheFunction · 0.85

Calls 3

loadCacheFilesMethod · 0.95
getCacheLoggerFunction · 0.85
DebugMethod · 0.65

Tested by

no test coverage detected