Reputation: 19723
I've implemented fragment caching on a view. More specifically on the comments section. It looks something like:
<% cache "video_#{@video.id}_comments" do %>
<div id="comments">
<%= render :partial => 'artists/videos/comments/comments' %>
</div>
<% end %>
In my comment controller, create action, I have:
....
if @comment.save
expire_fragment("#{@comment.commentable.class.to_s.downcase}_#{@comment.commentable.id}_comments")
In development, when a new comment is created. The cache is expired and when I reload the page, the new comment displays normally.
On Heroku, this is not the case. Is it because I should be using memcache? Or am I doing something wrong elsewhere?
Upvotes: 1
Views: 590
Reputation: 13583
Just an idea. Can you try:
Rails.cache.delete("views/"#{@comment.commentable.class.to_s.downcase}_#{@comment.commentable.id}_comments")
in the place of expire_fragment
Also, I strongly suggest using a cache store in heroku. Else, the default is memory store which is local to a dyno and not visible to other dynos. Also, your application memory will run out soon. Also, the dalli store provided by Heroku is super fast. Refer this doc
Upvotes: 3