Sha256: e7eb3b679580aed707f332f37fb0fd156bd7ac3424bf159b4ce2f0ee0c91ee09

Contents?: true

Size: 998 Bytes

Versions: 10

Compression:

Stored size: 998 Bytes

Contents

# = CacheObserver
#
# Expires caches.
module Calagator

class CacheObserver < ActiveRecord::Observer
  observe Event, Venue

  #---[ Unique methods ]--------------------------------------------------

  # 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.
  def self.daily_key_for(name, request=nil)
    return "#{name}@#{Time.zone.now.strftime('%Y%m%d')}"
  end

  # Expires all cached data.
  def self.expire_all
    Rails.logger.info "CacheObserver::expire_all: invoked"
    Rails.cache.clear
  end

  #---[ Triggers ]--------------------------------------------------------

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

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

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
calagator-1.0.0 app/observers/calagator/cache_observer.rb
grokus-1.0.0.9 app/observers/calagator/cache_observer.rb
grokus-1.0.0.8 app/observers/calagator/cache_observer.rb
grokus-1.0.0.7 app/observers/calagator/cache_observer.rb
grokus-1.0.0.6 app/observers/calagator/cache_observer.rb
grokus-1.0.0.5 app/observers/calagator/cache_observer.rb
grokus-1.0.0.3 app/observers/calagator/cache_observer.rb
grokus-1.0.0.2 app/observers/calagator/cache_observer.rb
grokus-1.0.0.1 app/observers/calagator/cache_observer.rb
calagator-1.0.0.rc3 app/observers/calagator/cache_observer.rb