Class: Platform::Cache

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

Class Method Summary collapse

Class Method Details

.cacheObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/platform/cache.rb', line 26

def self.cache
  @cache ||= begin
    if Platform::Config.cache_adapter == 'ActiveSupport::Cache'
      store_params = [Platform::Config.cache_store].flatten
      store_params[0] = store_params[0].to_sym
      ActiveSupport::Cache.lookup_store(*store_params)
    else
      eval(Platform::Config.cache_adapter)  
    end
  end
end

.decrement(key, amount = 1) ⇒ Object



63
64
65
66
# File 'lib/platform/cache.rb', line 63

def self.decrement(key, amount = 1)
  return unless enabled?
  cache.decrement(versioned_key(key), amount)
end

.delete(key, options = nil) ⇒ Object



53
54
55
56
# File 'lib/platform/cache.rb', line 53

def self.delete(key, options = nil)
  return unless enabled?
  cache.delete(versioned_key(key), options)
end

.enabled?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/platform/cache.rb', line 38

def self.enabled?
  Platform::Config.enable_caching?
end

.fetch(key, options = {}) ⇒ Object



46
47
48
49
50
51
# File 'lib/platform/cache.rb', line 46

def self.fetch(key, options = {})
  return yield unless enabled?
  cache.fetch(versioned_key(key), options) do 
    yield
  end
end

.get(key, options = {}) ⇒ Object



73
74
75
76
# File 'lib/platform/cache.rb', line 73

def self.get(key, options = {})
  return unless enabled?
  cache.get(key, options)
end

.increment(key, amount = 1) ⇒ Object



58
59
60
61
# File 'lib/platform/cache.rb', line 58

def self.increment(key, amount = 1)
  return unless enabled?
  cache.increment(versioned_key(key), amount)
end

.set(key, value, options = {}) ⇒ Object



68
69
70
71
# File 'lib/platform/cache.rb', line 68

def self.set(key, value, options = {})
  return unless enabled?
  cache.set(key, value, options)
end

.versioned_key(key) ⇒ Object



42
43
44
# File 'lib/platform/cache.rb', line 42

def self.versioned_key(key)
  "#{Platform::Config.cache_version}_#{key}"
end