class Rack::MiniProfiler::MemoryStore::CacheCleanupThread

Sub-class thread so we have a named thread (useful for debugging in Thread.list).

Public Class Methods

new(interval, cycle, store) click to toggle source
Calls superclass method
# File lib/mini_profiler/storage/memory_store.rb, line 8
def initialize(interval, cycle, store)
  super
  @store       = store
  @interval    = interval
  @cycle       = cycle
  @cycle_count = 1
end

Public Instance Methods

cleanup() click to toggle source
# File lib/mini_profiler/storage/memory_store.rb, line 31
def cleanup
  @store.cleanup_cache
  @cycle_count = 1
end
cycle_count() click to toggle source
# File lib/mini_profiler/storage/memory_store.rb, line 36
def cycle_count
  @cycle_count
end
increment_cycle() click to toggle source
# File lib/mini_profiler/storage/memory_store.rb, line 40
def increment_cycle
  @cycle_count += 1
end
should_cleanup?() click to toggle source
# File lib/mini_profiler/storage/memory_store.rb, line 16
def should_cleanup?
  @cycle_count * @interval >= @cycle
end
sleepy_run() click to toggle source

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.

# File lib/mini_profiler/storage/memory_store.rb, line 25
def sleepy_run
  cleanup if should_cleanup?
  sleep(@interval)
  increment_cycle
end