# Caching Warning

**URL:** <https://www.ruby-forum.com/t/caching-warning/169872>\
**Category:** Rails\
**Created:** [June 9, 2009, 9:14pm UTC](https://www.ruby-forum.com/t/caching-warning/169872 "2009-06-09T21:14:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [June 9, 2009, 9:14pm UTC](https://www.ruby-forum.com/t/caching-warning/169872/1 "2009-06-09T21:14:05Z")

</div>

This might be considered a bug… but I thought I’d at least warn folks.

I’m using fragment caching and the host name is in the key of the  
fragment. The problem is that this is the host name used in the URL.  
So, if you have two or more ways to get to the same host, you will have  
multiple versions of the same cached object.

For example, if your domain is [foo.com](http://foo.com) and your host is bar, then some  
users might use [http://bar/rest/of/path](http://bar/rest/of/path) and others might use  
[Foo.com](http://bar.foo.com/rest/of/path)

In one case, bar is the host and is used in the key for the fragments  
and in other cases [bar.foo.com](http://bar.foo.com) is. This creates a problem when you try  
to invalid a cached entity. If you are using a sweeper and the user  
comes in as bar and updates a database record, you flush the cache entry  
with bar in the name but not the cache entry with [bar.foo.com](http://bar.foo.com) in the  
name. You still have the old fragment cached up and some of your lusers  
will hit it.

I’m not sure quiet yet how to fix this. I want to somehow modify the  
host in the request to be the fully qualified hostname and not the short  
hand version.

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [June 10, 2009, 9:42am UTC](https://www.ruby-forum.com/t/caching-warning/169872/2 "2009-06-10T09:42:27Z")

</div>

On Jun 9, 8:14 pm, Perry S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> In one case, bar is the host and is used in the key for the fragments  
> and in other cases [bar.foo.com](http://bar.foo.com) is. This creates a problem when you try  
> to invalid a cached entity. If you are using a sweeper and the user  
> comes in as bar and updates a database record, you flush the cache entry  
> with bar in the name but not the cache entry with [bar.foo.com](http://bar.foo.com) in the  
> name. You still have the old fragment cached up and some of your lusers  
> will hit it.

Sort of makes sense - you could easily have different subdomains be  
different user accounts or something like that.

> I’m not sure quiet yet how to fix this. I want to somehow modify the  
> host in the request to be the fully qualified hostname and not the short  
> hand version.

apache/nginx rewrite rules can do this

Fred

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [June 10, 2009, 2:45pm UTC](https://www.ruby-forum.com/t/caching-warning/169872/3 "2009-06-10T14:45:13Z")

</div>

Frederick C. wrote:

> apache/nginx rewrite rules can do this

I’m worried about redirects. The server is behind a firewall. The  
browser thinks that [foo.outside.com](http://foo.outside.com) is different from foo. If I am  
authenticated to [foo.outside.com](http://foo.outside.com) and then foo happens to ask for  
authentication, the browser will ask me again instead of just sending  
what it already has.

I might be worried about nothing.

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [June 10, 2009, 2:50pm UTC](https://www.ruby-forum.com/t/caching-warning/169872/4 "2009-06-10T14:50:49Z")

</div>

On Jun 10, 1:45 pm, Perry S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Frederick C. wrote:
> 
> > apache/nginx rewrite rules can do this
> 
> I’m worried about redirects. The server is behind a firewall. The  
> browser thinks that [foo.outside.com](http://foo.outside.com) is different from foo. If I am  
> authenticated to [foo.outside.com](http://foo.outside.com) and then foo happens to ask for  
> authentication, the browser will ask me again instead of just sending  
> what it already has.

in that case it may be simpler to just fiddle the HTTP\_HOST variable

Fred

---

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [June 10, 2009, 2:58pm UTC](https://www.ruby-forum.com/t/caching-warning/169872/5 "2009-06-10T14:58:44Z")

</div>

Frederick C. wrote:

> On Jun 10, 1:45ï¿½pm, Perry S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Frederick C. wrote:
> > 
> > > apache/nginx rewrite rules can do this
> > 
> > I’m worried about redirects. ï¿½The server is behind a firewall. ï¿½The  
> > browser thinks that [foo.outside.com](http://foo.outside.com) is different from foo. ï¿½If I am  
> > authenticated to [foo.outside.com](http://foo.outside.com) and then foo happens to ask for  
> > authentication, the browser will ask me again instead of just sending  
> > what it already has.
> 
> in that case it may be simpler to just fiddle the HTTP\_HOST variable

Thats what I’m doing. Its actually a sequence of variables. I looked  
at how “host” was derived when a url rewrite is done. Its the  
forwarding host if set (which hit is in my case due to my apache set  
up), else HTTP\_HOST if set, else HTTP\_SERVER if set, else …

Its working at this point.

The alternative would be to pass :host =\> xxx in the hash when the cache  
fragments is created and deleted. That seems the safest but it hits  
multiple places.
