Module: RefinerycmsVarnish::PageExtension

Defined in:
lib/refinerycms_varnish/page_extension.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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
# File 'lib/refinerycms_varnish/page_extension.rb', line 4

def self.included(base)
  base.after_save :purge_page
  base.after_destroy :purge_page
  
  base.class_eval do
    
    private
    def purge_page
      
      if  ((self.respond_to?(:title_changed?) and self.title_changed?) or self.link_url_changed?) and self.show_in_menu

        # it seems that attributes possibly relevant to other pages have changed
        # -> we expire all urls
        ActionController::Base.purge "/", true

      elsif self.link_url and self.link_url.starts_with?("/")

        # by now we assume that no attributes relevant to other pages have
        # changed -> we expire this page only
        ActionController::Base.purge self.link_url

      else

        # by now we know that there is no link_url -> we expire this page only
        ActionController::Base.purge "/#{self.slug.name}"

      end
      
      if (path = RefinerySetting.find_or_set(:always_purge_path, '')).size > 0
        ActionController::Base.purge path
      end
      
    end
    
  end
end