Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Varnishd the right caching solution to use with Rails?

I want to cache full pages on our web application (thousands of pages) that are rendered by the Rails stack, but don't change very often. Each render is quite expensive in terms of resources.

My understanding of how Varnishd works is that when an initial call is made to a URL, Varnishd will check its cache store, a miss will take place and so the request will be passed through to Rails and resulting page which gets generated is then added to the Varnishd cache.

Any subsequent calls made to that URL and then served from the Varnishd cache, the Rails stack is not involved.

Is this correct or am I way off?

How can have my app tell Varnishd when a specific page has been updated & to reflect any changes made in its cache store?

Is Varnishd a good choice for this purpose?

Thanks for your help - I know these are very basic questions, but docs just don't make this clear (to me at least).

like image 312
Jason Avatar asked Jan 05 '11 23:01

Jason


People also ask

Is Varnish Cache good?

If configured correctly, Varnish Cache can easily make your website 1,000 times faster. Varnish uses the Varnish Configuration Language (VCL) to control the behavior of the cache.

Do I need Varnish Cache?

You can use Varnish to cache both dynamic and static content: this is an efficient solution to increase not only your website speed but also your server performance. According to its developers: “It can speed up delivery with a factor of 300 – 1000x, depending on your architecture. “

Is Varnish Cache Safe?

Varnish provides secure connections for both the client and the backend side. It means that the data shuffled between your Varnish server and the final user and the bytes between the origin server and Varnish are always encrypted, protecting privacy and avoiding data leaks.

What is Varnish cache used for?

Varnish Cache is a powerful, open source HTTP engine/reverse HTTP proxy that can speed up a website by up to 1000 percent by doing exactly what its name implies: caching (or storing) a copy of a webpage the first time a user visits.


1 Answers

To do dynamic cache invalidation, you can send purge.url {some regexp} from your application server over the management channel. For example, purge.url "^/some/page/$". However, from Rails, it's probably easiest to use the PURGE HTTP method. So instead of doing an HTTP GET, you'd do a PURGE against the same URI:

PURGE /some/page/ HTTP/1.0
Host: example.com

This request has to come in from localhost unless you override that in the configuration.

Some links:

  • http://www.varnish-cache.org/trac/wiki/VCLExamplePurging
  • http://www.varnish-cache.org/trac/wiki/Purging
  • http://kristianlyng.wordpress.com/2010/02/02/varnish-purges/
like image 84
Bob Aman Avatar answered Oct 29 '22 13:10

Bob Aman