Created
October 28, 2013 16:35
-
-
Save rafael/7200174 to your computer and use it in GitHub Desktop.
Cache page based on actionpack_page_caching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'fileutils' | |
| module Openair | |
| module CachePage | |
| # This methods come from action_pack/cache_page' | |
| # https://github.com/rails/actionpack-page_caching | |
| # We didn't need the whole gem. So I decided to get | |
| # just what we need :) | |
| def cache_page(content, path, extension = '.html', gzip = Zlib::BEST_COMPRESSION) | |
| path = page_cache_path(path, extension) | |
| FileUtils.makedirs(File.dirname(path)) | |
| File.open(path, 'wb+') { |f| f.write(content) } | |
| if gzip | |
| Zlib::GzipWriter.open(path + '.gz', gzip) { |f| f.write(content) } | |
| end | |
| end | |
| private | |
| def page_cache_path(path, extension = nil) | |
| page_cache_directory = "#{Rails.root.to_s}/public" | |
| page_cache_directory.to_s + '/' + path + extension | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment