Module: PageCache

Included in:
GallerySweeper, PictureSweeper
Defined in:
app/sweepers/page_cache.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sweep_allObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/sweepers/page_cache.rb', line 3

def self.sweep_all
  cache_dir = ActionController::Base.page_cache_directory
  # Delete index
  FileUtils.rm_r(cache_dir + '/index.html') rescue Errno::ENOENT

  # Delete Gallery and content
  FileUtils.rm_r(cache_dir + '/galleries.html') rescue Errno::ENOENT
  FileUtils.rm_r(Dir.glob(cache_dir + "/galleries/*")) rescue Errno::ENOENT
  FileUtils.rm_r(Dir.glob(cache_dir + "/galleries")) rescue Errno::ENOENT

  # Delete Pictures and content
  FileUtils.rm_r(cache_dir + '/pictures.html') rescue Errno::ENOENT
  FileUtils.rm_r(Dir.glob(cache_dir + "/pictures/*")) rescue Errno::ENOENT
  FileUtils.rm_r(Dir.glob(cache_dir + "/pictures/")) rescue Errno::ENOENT
end

Instance Method Details

#delete_cache_pagination_galleries(gallery) ⇒ Object

Delete the cache about pagination in galleries view



20
21
22
23
# File 'app/sweepers/page_cache.rb', line 20

def delete_cache_pagination_galleries(gallery)
  FileUtils.rm_r(Dir.glob(@cache_dir+"/galleries/page/*")) rescue Errno::ENOENT
  FileUtils.rm_r(Dir.glob(@cache_dir+"/galleries/#{gallery.permalink}/page/*")) rescue Errno::ENOENT
end

#delete_cache_pagination_pictures(picture) ⇒ Object

Delete the cache about pagination in pictures view



32
33
34
35
# File 'app/sweepers/page_cache.rb', line 32

def delete_cache_pagination_pictures(picture)
  FileUtils.rm_r(Dir.glob(@cache_dir+"/pictures/page/*")) rescue Errno::ENOENT
  FileUtils.rm_r(Dir.glob(@cache_dir+"/pictures/#{picture.permalink}.html")) rescue Errno::ENOENT
end

#delete_cache_pagination_tag(tag) ⇒ Object

Delete the cache about pagination in tags view



57
58
59
# File 'app/sweepers/page_cache.rb', line 57

def delete_cache_pagination_tag(tag)
  FileUtils.rm_r(Dir.glob(@cache_dir+"/tags/#{tag.permalink}/page/*")) rescue Errno::ENOENT
end

#expire_cache_galleries(gallery) ⇒ Object

Delete all cache on galleries view the index and all show



38
39
40
41
# File 'app/sweepers/page_cache.rb', line 38

def expire_cache_galleries(gallery)
  expire_page :controller => '/galleries', :action => :index
  expire_page :controller => '/galleries', :action => :show, :id => gallery
end

#expire_cache_pictures(picture) ⇒ Object

Delete all cache on pictures view the index and all show



26
27
28
29
# File 'app/sweepers/page_cache.rb', line 26

def expire_cache_pictures(picture)
  expire_page :controller => '/pictures', :action => :index
  expire_page :controller => '/pictures', :action => :show, :id => picture
end

#expire_cache_tags(picture) ⇒ Object

Delete all cache about old and new tag in this picture



44
45
46
47
48
49
50
51
52
53
54
# File 'app/sweepers/page_cache.rb', line 44

def expire_cache_tags(picture)
  picture.tags.each do |tag|
    expire_page :controller => '/tags', :action => :show, :id => tag
    delete_cache_pagination_tag(tag)
  end

  picture.old_tag.each do |tag|
    expire_page :controller => '/tags', :action => :show, :id => tag
    delete_cache_pagination_tag(tag)
  end
end

#expire_rootObject

expire /



62
63
64
# File 'app/sweepers/page_cache.rb', line 62

def expire_root
  expire_page '/'
end