# Apache + Mongrel Cluster Caching (cross server)

**URL:** <https://www.ruby-forum.com/t/apache-mongrel-cluster-caching-cross-server/89652>\
**Category:** Rails\
**Created:** [March 21, 2007, 10:05pm UTC](https://www.ruby-forum.com/t/apache-mongrel-cluster-caching-cross-server/89652 "2007-03-21T22:05:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [March 21, 2007, 10:05pm UTC](https://www.ruby-forum.com/t/apache-mongrel-cluster-caching-cross-server/89652/1 "2007-03-21T22:05:49Z")

</div>

Has anyone here successfully setup a system to take advantage of rails  
page/action caching when using a mongrel cluster that spans multiple  
servers? If so, could you shed some light on how you handled expiring  
cache across multiple mongrel servers (physically different machines)?

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [March 21, 2007, 10:52pm UTC](https://www.ruby-forum.com/t/apache-mongrel-cluster-caching-cross-server/89652/2 "2007-03-21T22:52:52Z")

</div>

I’m working on this now. I have two approaches:

1. (Implemented) - If you control the URLs, put the timestamp of the  
resource in the URL linking to it. eg url\_for(:product =\>  
product, :timestamp =\> product.modified\_at.to\_i)

2. Instead of using page caching, have Apache cache, use mod\_cache.  
Then, set the expires header very short - Apache will ask Rails for  
the resource. But don’t return it if it’s still okay - see  
[Client HTTP Caching in Rails - igvita.com](http://www.igvita.com/blog/2007/03/07/client-http-caching-in-rails/)

(I have the headers in #2 working but have not turned on mod\_cache  
yet)  
Let me know how your experience goes.

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [March 22, 2007, 4:26am UTC](https://www.ruby-forum.com/t/apache-mongrel-cluster-caching-cross-server/89652/3 "2007-03-22T04:26:21Z")

</div>

Action caching can be configured to use a shared fragment store - DRb  
or Memcache fragment stores are supplied. Expiry from any server will  
expiry the action for all servers, and, with Memcache, the store can  
be distributed over a set of servers for redundancy.

Page caching will need some form of sharing of the cache directory  
across machines - NFS would be the obvious choice, but I don’t know  
how reliable this is, or how Rails or Apache behave when there are  
network problems.

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [March 28, 2007, 12:55am UTC](https://www.ruby-forum.com/t/apache-mongrel-cluster-caching-cross-server/89652/4 "2007-03-28T00:55:27Z")

</div>

On 3/21/07, S. Robert J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 1. (Implemented) - If you control the URLs, put the timestamp of the  
> resource in the URL linking to it. eg url\_for(:product =\>  
> product, :timestamp =\> product.modified\_at.to\_i)

> 1. Instead of using page caching, have Apache cache, use mod\_cache.  
> Then, set the expires header very short - Apache will ask Rails for  
> the resource. But don’t return it if it’s still okay - see  
> [Client HTTP Caching in Rails - igvita.com](http://www.igvita.com/blog/2007/03/07/client-http-caching-in-rails/)

1. Use a SAN.

J.

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [March 28, 2007, 3:32am UTC](https://www.ruby-forum.com/t/apache-mongrel-cluster-caching-cross-server/89652/5 "2007-03-28T03:32:43Z")

</div>

I have it implemented and working for a long time using NFS mounts for  
the public directory. But you don’t really need NFS specifically.  
Anything you can mount and share across servers will work.

Bye,

Guy.

On 3/21/07, Justin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

–  
Family management on rails: [http://www.famundo.com](http://www.famundo.com)  
My development related blog: [http://devblog.famundo.com](http://devblog.famundo.com)
