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.



15
16
17
# File 'app/observers/calagator/cache_observer.rb', line 15

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

.expire_allObject

Expires all cached data.



20
21
22
23
# File 'app/observers/calagator/cache_observer.rb', line 20

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

Instance Method Details

#after_destroy(_record) ⇒ Object



32
33
34
35
# File 'app/observers/calagator/cache_observer.rb', line 32

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

#after_save(_record) ⇒ Object

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



27
28
29
30
# File 'app/observers/calagator/cache_observer.rb', line 27

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