class Rack::MiniProfiler::MemoryStore::CacheCleanupThread
Sub-class thread so we have a named thread (useful for debugging in Thread.list).
Public Class Methods
Source
# File lib/mini_profiler/storage/memory_store.rb, line 12 def initialize(interval, cycle, store) @store = store @interval = interval @cycle = cycle @cycle_count = 1 super end
Calls superclass method
Public Instance Methods
Source
# File lib/mini_profiler/storage/memory_store.rb, line 34 def cleanup @store.cleanup_cache @cycle_count = 1 end
Source
# File lib/mini_profiler/storage/memory_store.rb, line 39 def cycle_count @cycle_count end
Source
# File lib/mini_profiler/storage/memory_store.rb, line 43 def increment_cycle @cycle_count += 1 end
Source
# File lib/mini_profiler/storage/memory_store.rb, line 20 def should_cleanup? @cycle_count * @interval >= @cycle end
Source
# File lib/mini_profiler/storage/memory_store.rb, line 28 def sleepy_run cleanup if should_cleanup? sleep(@interval) increment_cycle end
We don’t want to hit the filesystem every 10s to clean up the cache so we need to do a bit of accounting to avoid sleeping that entire time. We don’t want to sleep for the entire period because it means the thread will stay live in hot deployment scenarios, keeping a potentially large memory graph from being garbage collected upon undeploy.