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.



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

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

.expire_allObject

Expires all cached data.



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

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

Instance Method Details

#after_destroy(record) ⇒ Object



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

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

#after_save(record) ⇒ Object

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



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

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