Class: Dato::Cache

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

Class Method Summary collapse

Class Method Details

.active?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/dato/cache.rb', line 13

def self.active?
  Dato::Config.cache.present?
end

.expires_inObject



17
18
19
# File 'lib/dato/cache.rb', line 17

def self.expires_in
  Dato::Config.cache.is_a?(Integer) ? Dato::Config.cache : 60.minutes
end

.fetch(cache_key, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/dato/cache.rb', line 3

def self.fetch(cache_key, &block)
  if active?
    Rails.cache.fetch(cache_key, expires_in: expires_in, namespace: namespace) do
      block.call
    end
  else
    block.call
  end
end

.namespaceObject



21
22
23
# File 'lib/dato/cache.rb', line 21

def self.namespace
  Dato::Config.cache_namespace
end