README.rdoc in itrigga-cache-0.2.1 vs README.rdoc in itrigga-cache-0.3.0
- old
+ new
@@ -25,9 +25,43 @@
This will
- call the block
- render the content
- cache the *rendered* output
- set the :content_type according to the pasted in value (defaults to 'text/html')
+
+== Content-type, respond_to and response status codes
+With controller caching, there are a couple of gotchas.
+- If you need to return a non-200 HTTP status code, set it in @status
+- The cached value will be the *return value* of the block
+- respond_to doesn't return anything - so it can break the nice and simple pattern
+
+So, if you're not using an explicit render statement, you'll need to render_to_string as the last action of your cache block:
+
+def tracker_stats
+ with_controller_cache( :key=>default_cache_key ) {
+ do_some_stuff_that_takes_a_long_time
+ @title = "#{@client.name} Tracker Stats"
+ @header = "#{@client.name} Tracker Stats"
+
+ render_to_string # <- this will be the cached value
+ }
+end
+
+If you're using respond_to, you need to do it like this:
+
+with_controller_cache(opts) do
+ respond_to do |format|
+ format.html{
+ @content = render_to_string
+ }
+ format.js {
+ @content_type = 'text/javascript'
+ @content = render_to_string
+ }
+ end
+ @content
+end
+
To bypass the cache just have the "freshen" => true key in the params (ie as a query string param). This will force fresh the cache
== Installation
In environment.rb: