Sha256: 149be1fc7d978ad7217755b59901f2d13cfb06e55d93cba4a5edcc94ec0b219a

Contents?: true

Size: 993 Bytes

Versions: 3

Compression:

Stored size: 993 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.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

3 entries across 3 versions & 1 rubygems

Version Path
calagator-1.0.0.rc2 app/observers/calagator/cache_observer.rb
calagator-1.0.0.rc1 app/observers/calagator/cache_observer.rb
calagator-0.0.1.pre1 app/observers/calagator/cache_observer.rb