class GraphiteAPI::Cache::Memory
Public Class Methods
new(options, timers=false)
click to toggle source
# File lib/graphite-api/cache.rb, line 8 def initialize options, timers=false timers.every(120) { clean(options[:cache]) } if timers end
Public Instance Methods
get(time, key)
click to toggle source
# File lib/graphite-api/cache.rb, line 12 def get time, key cache[time.to_i][key] end
set(time, key, value)
click to toggle source
# File lib/graphite-api/cache.rb, line 16 def set time, key, value cache[time.to_i][key] = value end
Private Instance Methods
cache()
click to toggle source
# File lib/graphite-api/cache.rb, line 22 def cache @cache ||= Hash.new {|h,k| h[k] = Hash.new} end
clean(max_age)
click to toggle source
# File lib/graphite-api/cache.rb, line 26 def clean max_age Logger.debug [:MemoryCache, :before_clean, cache] cache.delete_if {|t,k| Time.now.to_i - t > max_age } Logger.debug [:MemoryCache, :after_clean, cache] end