Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 48 lines (42 sloc) 1.398 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

#
# Base Newscloud Sweeper; extend from this
#
class NewscloudSweeper < ActionController::Caching::Sweeper
  def expire(item = nil) end
  def expire_all(item = nil) end
  def self.expire(item = nil) end
  def self.expire_all(item = nil) end

  def self.expire_class klass, namespace = nil
    namespace ||= '*'
    key = "#{klass.name.downcase}:view_object_namespace_deps:#{namespace}"
    keys = $redis.keys(key)

    #return $redis.sunion(*($redis.keys(key))).map {|vo_name| vo_name.split(/:/).inject(nil) {|m,id| m.nil? ? id.classify.constantize : m.find(id) } }
    if keys.any?
      $redis.sunion(*(keys)).each do |key_name|
        if key_name =~ /^view_object:([0-9]+)$/
          view_object = ViewObject.find_by_id($1)
          view_object.uncache_deps if view_object
        end
      end
    end
  end

  def self.expire_new_item_widgets
    [Vote, PfeedItem, ItemAction, ItemScore].each do |klass|
      self.expire_class(klass)
    end
  end

  def self.expire_instance item
    keys = $redis.keys(item.model_deps_key)
    if keys.any?
      $redis.sunion(item.model_deps_key).each do |key_name|
        if key_name =~ /^view_object:([0-9]+)$/
          view_object = ViewObject.find_by_id($1)
          view_object.uncache_deps if view_object
        end
      end
    end

    # TODO:: stop this
    self.expire_new_item_widgets
    return self.expire_class(item.class)
  end
end
Something went wrong with that request. Please try again.