aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/request_controller.rb
diff options
context:
space:
mode:
authorFrancis Irving <francis@mysociety.org>2010-05-19 15:08:53 +0100
committerFrancis Irving <francis@mysociety.org>2010-05-19 15:08:53 +0100
commitecf920001a80d4eaa4fa34c7c465fe7e00964f32 (patch)
tree14e2b137684af6806b4128aa797149eba07742c8 /app/controllers/request_controller.rb
parent76abcd06b6531e15846d126431fc0edbc705f760 (diff)
Do the cacheing ourselves.
Diffstat (limited to 'app/controllers/request_controller.rb')
-rw-r--r--app/controllers/request_controller.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 120bb38ce..1357f993b 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -548,7 +548,8 @@ class RequestController < ApplicationController
key = params.merge(:only_path => true)
key_path = foi_fragment_cache_path(key)
- if cached = read_fragment(key_path)
+ if File.exists?(key_path)
+ cached = File.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)
@@ -557,7 +558,11 @@ class RequestController < ApplicationController
yield
- write_fragment(key_path, response.body)
+ # write it to the fileystem ourselves, so is just a plain file. (The
+ # 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)
+ File.open(key_path, 'wb') {|f| f.write(response.body) }
end
def get_attachment
@@ -580,7 +585,7 @@ class RequestController < ApplicationController
# the same cache code in cache_attachments above will display them.
key = params.merge(:only_path => true)
key_path = foi_fragment_cache_path(key)
- image_dir = File.dirname(ActionController::Base.cache_store.cache_path + "/views" + key_path)
+ image_dir = File.dirname(key_path)
FileUtils.mkdir_p(image_dir)
html, wrapper_id = @attachment.body_as_html(image_dir)