I was facing some problems with fragment caching. Let's suppose I have a website called mywebsite.com. My customers use to reach my website typing http://www.mywebsite.com on their browsers. While they are browsing some pages, I can see the fragments (where I used <% cache do %><% end %>) on the app_root/tmp/cache/ directory, ok, works fine.
But I use to go to my website WITHOUT "www", so I type http://mywebsite.com, take a look on my fragments directory, and, surprise, I have a www.mywebsite.com under my app_root/tmp/cache directory. And worst yet, if my DNS goes down and I use my website IP address to go there, I have another directory on the cache.
So, we have some problems here because we're caching 3 times the same info, what can be a disk size problem and a bigger problem if we use the non-www version to make some changes and update (expire) just one version of the fragments. The other ones will remains outdated and that will make some mess.
I was checking caching.rb and noticed that the fragment caching path is created by the fragment_cache_key method and I changed it to verify if the parameter hash have a :only_path option. If not, it's added one with the true value.
The :only_path option, as the document says, returns the relative URL omitting the protocol, host name, and port, so all that remains are just the controller, action and parameters. So, suppose I have a "test" controller and a "show" action, the app_root/tmp/cache/ directory will have a subdirectory called "test" with a "show.cache" file inside of there, no matter for which URL I accessed it, because it stripped it.