# = CacheObserver
#
# Expires caches.
class CacheObserver < ActiveRecord::Observer
  observe :event
  observe :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
    logit "invoked"
    Rails.cache.clear
  end

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

  def after_save(record)
    logit "invoked"
    self.class.expire_all
  end

  def after_destroy(record)
    logit "invoked"
    self.class.expire_all
  end
end

# = CacheObserver
#
# Expires caches.
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
    logit "invoked"
    Rails.cache.clear
  end

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

  def after_save(record)
    logit "invoked"
    self.class.expire_all
  end

  def after_destroy(record)
    logit "invoked"
    self.class.expire_all
  end
end

Fix CacheObserver to expire events.
Fix CacheObserver to expire events.

The Rails API for Observers has changed back and forth over the way the
"observe" call works, between having a separate call for each model and
having a single call for all models, and it's apparently the later.
