diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application_controller.rb | 21 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 9 |
2 files changed, 21 insertions, 9 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0f287f2e4..c0543ff9f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -101,17 +101,32 @@ class ApplicationController < ActionController::Base path = path.sub("/request/", "/request/" + first_three_digits + "/") return path end + def foi_fragment_cache_path(param) path = foi_fragment_cache_part_path(param) path = "/views" + path - return File.join(self.cache_store.cache_path, path) + foi_cache_path = File.join(File.dirname(__FILE__), '../../cache') + return File.join(foi_cache_path, path) end def foi_fragment_cache_all_for_request(info_request) + # return stub path so admin can expire it first_three_digits = info_request.id.to_s()[0..2] path = "views/request/#{first_three_digits}/#{info_request.id}" - return File.join(self.cache_store.cache_path, path) + foi_cache_path = File.join(File.dirname(__FILE__), '../../cache') + return File.join(foi_cache_path, path) + end + def foi_fragment_cache_exists?(key_path) + return File.exists?(key_path) + end + def foi_fragment_cache_read(key_path) + cached = File.read(key_path) + end + def foi_fragment_cache_write(key_path, content) + FileUtils.mkdir_p(File.dirname(key_path)) + File.atomic_write(key_path) do |f| + f.write(content) + end end - private # Check the user is logged in diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 4588ef369..007cef5d1 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -563,8 +563,8 @@ class RequestController < ApplicationController key = params.merge(:only_path => true) key_path = foi_fragment_cache_path(key) - if File.exists?(key_path) - cached = File.read(key_path) + if foi_fragment_cache_exists?(key_path) + cached = foi_fragment_cache_read(key_path) IncomingMessage # load global filename_to_mimetype XXX should move filename_to_mimetype to proper namespace response.content_type = filename_to_mimetype(params[:file_name].join("/")) or 'application/octet-stream' render_for_text(cached) @@ -577,10 +577,7 @@ class RequestController < ApplicationController # various fragment cache functions using Ruby Marshall to write the file # which adds a header, so isnt compatible with images that have been # extracted elsewhere from PDFs) - FileUtils.mkdir_p(File.dirname(key_path)) - File.atomic_write(key_path) do |f| - f.write(response.body) - end + foi_fragment_cache_write(key_path, response.body) end def get_attachment |