MCPcopy Create free account
hub / github.com/erans/pgsqlite / maybe_cleanup

Method maybe_cleanup

src/cache/ttl_cache.rs:356–377  ·  view source on GitHub ↗

Check if cleanup should be performed

(&self)

Source from the content-addressed store, hash-verified

354
355 /// Check if cleanup should be performed
356 fn maybe_cleanup(&self) {
357 let last_cleanup = *self.last_cleanup.read();
358 if last_cleanup.elapsed() >= self.config.cleanup_interval {
359 self.cleanup();
360 }
361
362 // Additional memory leak prevention: force cleanup if cache grows too large
363 let current_size = self.stats.read().total_size_bytes;
364 let size_threshold = self.config.memory_pressure_threshold * 1024 * 1024; // Convert MB to bytes
365
366 if current_size > size_threshold && self.config.memory_pressure_enabled {
367 debug!("Cache size ({} bytes) exceeds threshold ({} bytes), forcing cleanup",
368 current_size, size_threshold);
369 self.cleanup();
370
371 // If still too large after cleanup, perform emergency eviction
372 let size_after_cleanup = self.stats.read().total_size_bytes;
373 if size_after_cleanup > size_threshold {
374 self.emergency_memory_eviction();
375 }
376 }
377 }
378
379 /// Handle memory pressure by evicting entries
380 fn maybe_handle_memory_pressure(&self) {

Callers 2

getMethod · 0.45

Calls 3

readMethod · 0.80
cleanupMethod · 0.45

Tested by

no test coverage detected