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

Method Clear

internal/cache/cache.go:291–318  ·  view source on GitHub ↗

Clear removes all items from the cache.

()

Source from the content-addressed store, hash-verified

289
290// Clear removes all items from the cache.
291func (c *FileCache) Clear() error {
292 c.mutex.Lock()
293 defer c.mutex.Unlock()
294
295 // Clear in-memory cache and LRU list
296 c.inMemory = make(map[string]*list.Element)
297 c.lruList = list.New()
298
299 // If persisted, remove all cache files
300 if c.persisted {
301 files, err := os.ReadDir(c.dir)
302 if err != nil {
303 return fmt.Errorf("failed to read cache directory: %w", err)
304 }
305
306 for _, file := range files {
307 if file.IsDir() || filepath.Ext(file.Name()) != ".json" {
308 continue
309 }
310
311 if err := os.Remove(filepath.Join(c.dir, file.Name())); err != nil {
312 return fmt.Errorf("failed to remove cache file %s: %w", file.Name(), err)
313 }
314 }
315 }
316
317 return nil
318}
319
320// Close implements the Cache.Close method for FileCache
321// This is a no-op for FileCache since it doesn't maintain any resources that need explicit closing.

Callers

nothing calls this directly

Calls 1

NameMethod · 0.65

Tested by

no test coverage detected