Module: LLT::Helpers::PrimitiveCache

Defined in:
lib/llt/helpers/primitive_cache.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(obj) ⇒ Object



6
7
8
# File 'lib/llt/helpers/primitive_cache.rb', line 6

def self.included(obj)
  obj.extend(ClassMethods)
end

Instance Method Details

#cacheObject



18
19
20
# File 'lib/llt/helpers/primitive_cache.rb', line 18

def cache
  self.class.cache
end

#cached(key) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/llt/helpers/primitive_cache.rb', line 22

def cached(key)
  if @cache_enabled
    self.class.cache.fetch(key) { yield } #[key] ||= yield # with Dalli use
  else
    yield
  end
end

#disable_cacheObject



14
15
16
# File 'lib/llt/helpers/primitive_cache.rb', line 14

def disable_cache
  @cache_enabled = false
end

#enable_cacheObject



10
11
12
# File 'lib/llt/helpers/primitive_cache.rb', line 10

def enable_cache
  @cache_enabled = true
end