aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/application_helper.rb
diff options
context:
space:
mode:
authorFrancis Irving <francis@mysociety.org>2010-09-06 09:59:24 +0100
committerFrancis Irving <francis@mysociety.org>2010-09-06 09:59:24 +0100
commit8912d36b02a44ac07e9a83214d4486159cc95863 (patch)
treea935a945d28feb90704bbd980f485c6ae143c675 /app/helpers/application_helper.rb
parent539e3d0f3cdf2aee836ea7b784e91d4ad1a9fbf1 (diff)
Change the foi_cache to be explicit everywhere, so Interlock can use the
rails cache
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r--app/helpers/application_helper.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 08908abee..f2a02962e 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -62,8 +62,25 @@ module ApplicationHelper
# Use our own algorithm for finding path of cache
def foi_cache(name = {}, options = nil, &block)
- name = @controller.foi_fragment_cache_part_path(name)
- @controller.fragment_for(output_buffer, name, options, &block)
+ if @controller.perform_caching
+ #name = @controller.foi_fragment_cache_part_path(name)
+ #@controller.fragment_for(output_buffer, name, options, &block)
+
+ key = name.merge(:only_path => true)
+ key_path = @controller.foi_fragment_cache_path(key)
+
+ if @controller.foi_fragment_cache_exists?(key_path)
+ cached = @controller.foi_fragment_cache_read(key_path)
+ output_buffer.concat(cached)
+ return
+ end
+
+ pos = output_buffer.length
+ content = block.call
+ @controller.foi_fragment_cache_write(key_path, output_buffer[pos..-1])
+ else
+ block.call
+ end
end
end