Notes posted by concept47

RSS feed
August 15, 2013 - (v3.2.1 - v3.2.13)
0 thanks

expires_in option

You can actually pass in an expires_in option that sets how long Rails should show the fragment before deleting it so as an example …

<% cache('homepage_sidebar', :expires_in => 10.minutes) do %>
<% end %>

This only used to work with memcached but it now works with other types of Rails stores, MemoryStore, FileStore (had to use a plugin to get this behavior before) etc etc

So in your controller. You’d just do …

@posts = Posts.all if fragment_exists?('homepage_sidebar') 

to avoid performing a pointless SQL query.

April 27, 2013 - (v3.1.0 - v3.2.13)
4 thanks
April 10, 2013 - (v3.2.1 - v3.2.13)
2 thanks

be aware that this writes to tmp/cache

Its supposed to be http caching, but Rails will actually cache the response to whatever you specified as the cache store, *as well*, but only if you specify :public => true. The default is filestore so it will try to write to tmp/cache.

Only a problem if you don’t have the proper permissions set, in that scenario your apache/nginx logs could fill up very quickly with “permission denied errors”

Full explanation is here http://blog.tonycode.com/archives/418