About a month ago I launched my community engine site into the wild. At the time, I had some caching issues with the front page. I read up on how caching works in rails and looked at the code a bit, but everything looked OK. So I figured it was best to disable caching for the site_index action and swore to revisit the issue at a later time.
I'm running my production site on mod_passenger so I also limited the number of processes to 1. I figured that if the cache was being stored in memory, then different processes could be serving from different caches. Since the problem was hit or miss it seemed like this could also be the issue. (And with a small site running on a VPS with limited memory I wasn't yet worried about scalability.) Anyway, I recently noticed a problem with comments that weren't updating. I received an email that someone commented on my post, but I could only see the comment if I was logged in. I figured it was a caching problem so I restarted the server and the problem went away. Here are some things I found while investigating the issue, and an issue I am still having. Original Problem I tracked part of the problem down to the fact that the comment sweeper wasn't clearing all copies in the cache. My development.log file showed that the comment_sweeper was clearing /jtgeibel/posts/7- testing (among other things), but it wasn't clearing /posts/show/7- testing (the cache fragment that is actually being hit). I looked at the code and made the following change: - expire_action :controller => 'posts', :action => 'show', :id => record.commentable , :user_id => record.commentable.user + expire_action :controller => 'posts', :action => 'show', :id => record.commentable >From what I can tell, rails is only clearing the cache for the more specific route containing a user_id. However, its the action posts/ show that is actually being cached. With this fix, I now see the fragment cache being cleared in the log, but I'm still having one very strange problem. New Problem I can see in the development log that the cache is being cleared, but the first time I view the page (after logging out) I actually get a cache hit. If I refresh the page again, I see the updated page. Here is a commented portion of what I am seeing in my log file. $ cat ../../../log/development.log |grep fragment # ensure cache is full before posting a comment Cached fragment hit: views/dev.pittsburghgardenexperiment.org/posts/ show/7-testing (0.1ms) # commenting expires caches Expired fragment: views/dev.pittsburghgardenexperiment.org/application/ footer_content (0.1ms) Expired fragment: views/dev.pittsburghgardenexperiment.org/application/ footer_content (0.1ms) Expired fragment: views/dev.pittsburghgardenexperiment.org/posts/show/ 7-testing (0.1ms) Expired fragment: views/dev.pittsburghgardenexperiment.org/index (0.1ms) Expired fragment: views/dev.pittsburghgardenexperiment.org/categories/ 4-Talk (0.1ms) # logout and refresh and we get a cache hit Cached fragment hit: views/dev.pittsburghgardenexperiment.org/posts/ show/7-testing (0.1ms) # refresh again and we get a hit, followed by a miss in the same request. The correct content is rendered. Cached fragment hit: views/dev.pittsburghgardenexperiment.org/posts/ show/7-testing (0.1ms) Cached fragment miss: views/dev.pittsburghgardenexperiment.org/posts/ show/7-testing (0.1ms) Any thoughts on why I'm getting stale data on the first request? Or why the second request has a hit, followed by a miss? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CommunityEngine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/communityengine?hl=en -~----------~----~----~----~------~----~------~--~---
