Sha256: ed028720717ab8fbef50ad79ea645ad6a08cc5f9d532451f84394c96d081c974

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

module Refinery
  module PhotoGallery
    module Admin
      class AlbumSweeper < ActionController::Caching::Sweeper
        observe Album


        def sweep_album(album)
          expire_fragment("refinery/photo_gallery/albums/#{album.id}")
        end

        def sweep_album_with_photos(album)
          sweep_album(album)

          # only file store supports regexp
          begin
            # This is slow, but I was unable to get the actual cache folder path.
            expire_fragment( %r{refinery/photo_gallery/albums/#{photo.album_id}/page/\d*})
          rescue NotImplementedError
            Rails.cache.clear
            warn "**** [REFINERY PHOTO GALLERY] The cache store you are using is not compatible with this engine. Only file_store is supported. Clearing entire cache instead ***"
          ensure
            return true
          end
        end

        alias_method :after_create,  :sweep_album
        alias_method :after_update,  :sweep_album
        alias_method :after_destroy, :sweep_album_with_photos
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
refinerycms-photo-gallery-0.3.0 app/sweepers/refinery/photo_gallery/admin/album_sweeper.rb
refinerycms-photo-gallery-0.2.0 app/sweepers/refinery/photo_gallery/admin/album_sweeper.rb
refinerycms-photo-gallery-0.1.2 app/sweepers/refinery/photo_gallery/admin/album_sweeper.rb
refinerycms-photo-gallery-0.1.1 app/sweepers/refinery/photo_gallery/admin/album_sweeper.rb
refinerycms-photo-gallery-0.1.0 app/sweepers/refinery/photo_gallery/admin/album_sweeper.rb