Sha256: ef4035ba2e56c95587e6a46215669d83317ad8681ea3042324b214744ad3beb9

Contents?: true

Size: 1.25 KB

Versions: 21

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module PagesCore
  module StaticCache
    class PageCacheHandler
      def cache_page(controller, _request, _response)
        controller.class.page_cache_directory = page_cache_directory
        controller.cache_page
      end

      def cache_page_permanently(controller, _request, _response)
        controller.class.page_cache_directory = permanent_page_cache_directory
        controller.cache_page
      end

      def purge!
        return unless PagesCore::CacheSweeper.enabled

        clear_directory(page_cache_directory)
        clear_directory(permanent_page_cache_directory)
      end

      def sweep!
        return unless PagesCore::CacheSweeper.enabled

        PagesCore::SweepCacheJob.perform_later
      end

      def sweep_now!
        return unless PagesCore::CacheSweeper.enabled

        clear_directory(page_cache_directory)
      end

      private

      def cache_root
        Rails.public_path
      end

      def clear_directory(path)
        return unless File.exist?(path)

        FileUtils.rm_rf(Dir.glob("#{path}/*"))
      end

      def page_cache_directory
        cache_root.join("static_cache")
      end

      def permanent_page_cache_directory
        cache_root.join("cache")
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
pages_core-3.15.5 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.15.4 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.15.3 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.15.2 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.15.1 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.14.0 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.13.0 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.12.7 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.12.6 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.12.5 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.12.4 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.12.3 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.12.2 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.12.1 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.12.0 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.11.3 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.11.2 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.11.1 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.11.0 lib/pages_core/static_cache/page_cache_handler.rb
pages_core-3.10.2 lib/pages_core/static_cache/page_cache_handler.rb