Class: Calagator::CacheObserver

Inherits:
ActiveRecord::Observer
  • Object
show all
Defined in:
app/observers/calagator/cache_observer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.daily_key_for(name, _request = nil) ⇒ Object

Returns a cache key string for the day, e.g. “20080730”. It’s used primarily by the #cache_if calls in views. The optional request object provides a HTTP_HOST so that caching can be done for a particular hostname.



13
14
15
# File 'app/observers/calagator/cache_observer.rb', line 13

def self.daily_key_for(name, _request = nil)
  "#{name}@#{Time.zone.now.strftime('%Y%m%d')}"
end

.expire_allObject

Expires all cached data.



18
19
20
21
# File 'app/observers/calagator/cache_observer.rb', line 18

def self.expire_all
  Rails.logger.info 'CacheObserver::expire_all: invoked'
  Rails.cache.clear
end

Instance Method Details

#after_destroy(_record) ⇒ Object



30
31
32
33
# File 'app/observers/calagator/cache_observer.rb', line 30

def after_destroy(_record)
  Rails.logger.info 'CacheObserver#after_destroy: invoked'
  self.class.expire_all
end

#after_save(_record) ⇒ Object

—[ Triggers ]——————————————————–



25
26
27
28
# File 'app/observers/calagator/cache_observer.rb', line 25

def after_save(_record)
  Rails.logger.info 'CacheObserver#after_save: invoked'
  self.class.expire_all
end