Module: Cachet

Defined in:
lib/cachet.rb,
lib/cachet/cacheable.rb,
lib/cachet/file_store.rb

Defined Under Namespace

Modules: Cacheable Classes: FileStore

Class Method Summary collapse

Class Method Details

.cache(entity, key) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cachet.rb', line 13

def cache (entity, key)
  if enabled
    cached_item = storage.read(entity, key)
    if not cached_item
      cached_item = yield
      storage.write(entity, key, cached_item)
      Cachet.logger.info "#{entity} with key:#{key} could not found in cache. Evaluated and written to cache"
    else
      Cachet.logger.info "#{entity} with key:#{key} found in cache."
    end
    cached_item
  else
    yield
  end
end

.invalidate(entity, key) ⇒ Object



29
30
31
32
33
34
# File 'lib/cachet.rb', line 29

def invalidate (entity, key)
  if enabled
    storage.purge(entity, key)
    Cachet.logger.info "#{entity} with key:#{key} invalidated."
  end
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Cachet)

    the object that the method was called on



9
10
11
# File 'lib/cachet.rb', line 9

def setup
  yield self
end