lib/glue/sweeper.rb in nitro-0.31.0 vs lib/glue/sweeper.rb in nitro-0.40.0

- old
+ new

@@ -11,32 +11,44 @@ # FIXME: find a better name. #++ module Sweeper include Aspects - + + #-- + # Inject the sweepers *after* the event to have a valid + # oid. + #++ + before "sweep_affected(:insert)", :on => :og_insert before "sweep_affected(:update)", :on => :og_update before "sweep_affected(:delete)", :on => :og_delete # Expires (deletes) a cached page from the file system. + # + # == Input + # + # * relative = if set to true, prepends the controller + # mount path. #-- # FIXME: replace with 'extend Nitro::Caching::Output' ? # this way we wont have to sync the same code in two different # places. # If you change this method, don't forget the Caching::Output # expire method. #++ - def self.expire(name, klass) - begin - filename = "#{Server.public_root}/#{klass.ann.self.controller.mount_path}/#{name}".squeeze('/') - Logger.debug "Sweeper expired cache file '#{filename}'" if $DBG - FileUtils.rm_rf(filename) - rescue Object - # gmosx: is this the right thing to do? + def self.expire(name, klass, relative = false) + if relative and controller = klass.ann.self[:controller] + filename = "#{Server.public_root}/#{controller.mount_path}/#{name}.html".squeeze('/') + else + filename = "#{Server.public_root}/#{name}.html".squeeze('/') end + Logger.debug "Sweeper expired cache file '#{filename}'" if $DBG + FileUtils.rm_rf(filename) + rescue Object => ex + # ignore any error. end private # If needed pass the calling action symbol to allow @@ -50,16 +62,21 @@ def sweep_affected(action = :all) end alias_method :expire_affected, :sweep_affected - #-- - # Generally you don't override this. - #++ + # Called from an action that modifies the model to expire + # affected (dependend) cached pages. Generally you don't + # override this method. + # + # == Input + # + # * relative = if set to true, prepends the controller + # mount path. - def expire_affected_output(name) - Sweeper.expire(name, self.class) + def expire_affected_output(name, relative = true) + Sweeper.expire(name, self.class, relative) end alias_method :expire_output, :expire_affected_output # Expire affected cached fragments. @@ -69,7 +86,5 @@ alias_method :expire_fragment, :expire_affected_fragment end end - -# * George Moschovitis <gm@navel.gr>