# How can I specify the location of the fragment cache?

**URL:** <https://www.ruby-forum.com/t/how-can-i-specify-the-location-of-the-fragment-cache/114696>\
**Category:** Rails\
**Created:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/how-can-i-specify-the-location-of-the-fragment-cache/114696 "2007-09-17T13:24:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/how-can-i-specify-the-location-of-the-fragment-cache/114696/1 "2007-09-17T13:24:19Z")

</div>

I am using fragment caching - the cache gets stored under RAILS\_ROOT/  
tmp/cache/www.mysite.com but if someone goes to [http://mysite.com](http://mysite.com) (no  
www) then, a _second_ cache gets stored at RAILS\_ROOT/tmp/cache/  
[mysite.com](http://mysite.com) - from this point on, the cache is hit at both URL  
locations but I end up with 2X the DB hits and 2X over-the-wire web  
service calls etc I really need.

This is turning out to be really really expensive. How can I avoid  
this?

Any ideas?

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [September 17, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/how-can-i-specify-the-location-of-the-fragment-cache/114696/2 "2007-09-17T13:25:35Z")

</div>

On Fri, 14 Sep 2007, raghus wrote:

> I am using fragment caching - the cache gets stored under RAILS\_ROOT/  
> tmp/cache/www.mysite.com but if someone goes to [http://mysite.com](http://mysite.com) (no  
> www) then, a _second_ cache gets stored at RAILS\_ROOT/tmp/cache/  
> [mysite.com](http://mysite.com) - from this point on, the cache is hit at both URL  
> locations but I end up with 2X the DB hits and 2X over-the-wire web  
> service calls etc I really need.
> 
> This is turning out to be really really expensive. How can I avoid  
> this?

You can ensure they always visit the non-www version of your domain  
name. Here’s an Apache rewrite rule for that:

RewriteCond %{HTTP\_HOST} !^mysite.com$ [NC]  
RewriteRule ^(.\*) [http://mysite.com/$1](http://mysite.com/$1) [L,R=301]

–  
Greg D.  
Cyberfusion Consulting  
[http://cyberfusionconsulting.com/](http://cyberfusionconsulting.com/)

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [September 25, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/how-can-i-specify-the-location-of-the-fragment-cache/114696/3 "2007-09-25T23:05:00Z")

</div>

> Any ideas?  
> Not a solution to your problem directly, but you may want to consider  
> 301  
> redirecting all requests to [mysite.com](http://mysite.com) to [www.mysite.com](http://www.mysite.com).

I know that Google will punish your page rankings if it sees the same  
content in multiple domains…

As a side effect it would also solve your problem…

-philip

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [September 25, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/how-can-i-specify-the-location-of-the-fragment-cache/114696/4 "2007-09-25T23:08:12Z")

</div>

That’s an idea that would have the side-effect of solving my problem  
yes, but I don’t believe Google will punish PR between www and a plain  
[site.com](http://site.com). As you say multiple domains: perhaps between [alpha.com](http://alpha.com) and  
[beta.com](http://beta.com) if there’s exactly the same content, then… maybe.

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [September 25, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/how-can-i-specify-the-location-of-the-fragment-cache/114696/5 "2007-09-25T23:09:57Z")

</div>

Greg D. wrote:

> You can ensure they always visit the non-www version of your domain  
> name. Here’s an Apache rewrite rule for that:
> 
> RewriteCond %{HTTP\_HOST} !^mysite.com$ [NC]  
> RewriteRule ^(.\*) [http://mysite.com/$1](http://mysite.com/$1) [L,R=301]

Beware. If you have multiple sites running under the same domain this  
will lead to trouble with cookies and IE. That is if you have both  
[example.com](http://example.com) and [anotherapp.example.com](http://anotherapp.example.com).

–  
Cheers,

- Jacob A.

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [September 25, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/how-can-i-specify-the-location-of-the-fragment-cache/114696/6 "2007-09-25T23:10:31Z")

</div>

You may be right… now that I think about it our problem was the  
individual hostnames vs www.

It definitely punished us for that.
