Class: FnordMetric::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/fnordmetric/cache.rb

Class Method Summary collapse

Class Method Details

.get(cache_key) ⇒ Object



14
15
16
17
18
# File 'lib/fnordmetric/cache.rb', line 14

def self.get(cache_key)
  item = self.where(:cache_key => cache_key).last
  return nil unless item
  item.data.keys == ["value"] ? item.data["value"] : item.data
end

.store!(cache_key, data) ⇒ Object

field :cache_key, :type => String

field :data, :type => Hash


9
10
11
12
# File 'lib/fnordmetric/cache.rb', line 9

def self.store!(cache_key, data)
  data = { :value => data } unless data.is_a?(Hash)
  self.create(:cache_key => cache_key, :data => data)
end