Module: Rack::PageCaching::ActionController
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rack/page_caching/action_controller.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION) ⇒ Object
- #expire_page(options = {}) ⇒ Object
Instance Method Details
#cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rack/page_caching/action_controller.rb', line 35 def cache_page(content = nil, = nil, gzip = Zlib::BEST_COMPRESSION) return unless self.class.perform_caching path = case when Hash url_for(.merge(only_path: true, format: params[:format])) when String else request.path end path = path.chomp('/') if (type = ::Mime::LOOKUP[self.content_type]) && (type_symbol = type.symbol).present? path = "#{path}.#{type_symbol}" unless /#{type_symbol}\z/.match(path) end Rack::PageCaching::Cache.write_file( Array(content || response.body), path, Rack::PageCaching::Utils.gzip_level(gzip) ) end |
#expire_page(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rack/page_caching/action_controller.rb', line 19 def expire_page( = {}) return unless self.class.perform_caching if .is_a?(Hash) if [:action].is_a?(Array) [:action].each do |action| Rack::PageCaching::Cache.delete(url_for(.merge(only_path: true, action: action))) end else Rack::PageCaching::Cache.delete(url_for(.merge(only_path: true))) end else Rack::PageCaching::Cache.delete() end end |