Welcome! Log In Create A New Profile

Advanced

cache static content in memory

Posted by nfn 
cache static content in memory
May 28, 2009 02:54PM
Hi,

I'm using nginx with apache2 + mod_php.
Php pages are proxied to apache and nginx handles all static files (css, js, png, jpg, gif).
I have lots of small files (forum design + smilies) ...

Can nginx cache theses files in memory? How?
If so, do I have any benefit with this approach?
Is this faster than serving from disk?

Thanks

N
J
Re: cache static content in memory
May 28, 2009 03:37PM
Hi,

your system has already a file cache memory. It does the trick.
If you want to use nginx cache capabilities, you can make nginx
reverse proxies all requests to apache (even static ones) and set up a
cache (proxy_cache* directives). But ningx will put cached files on
disk et read them on demand. It will benefits of system cache as well.

I asked myself the same question weeks ago but in my case static files
were not on a local disk but on a NFS shared disk. So I let apache to
serve statiques pages as well and cache them localy.

Hope it helps

2009/5/28 nfn <nginx-forum@nginx.us>:
> Hi,
>
> I'm using nginx with apache2 + mod_php.
> Php pages are proxied to apache and nginx handles all static files (css, js, png, jpg, gif).
> I have lots of small files (forum design + smilies) ...
>
> Can nginx cache theses files in memory? How?
> If so, do I have any benefit with this approach?
> Is this faster than serving from disk?
>
> Thanks
>
> N
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2465,2465#msg-2465
>
>
>
Re: cache static content in memory
May 28, 2009 05:26PM
On Thu, 2009-05-28 at 14:54 -0400, nfn wrote:
> Hi,
>
> I'm using nginx with apache2 + mod_php.
> Php pages are proxied to apache and nginx handles all static files (css, js, png, jpg, gif).
> I have lots of small files (forum design + smilies) ...
>
> Can nginx cache theses files in memory? How?
> If so, do I have any benefit with this approach?
> Is this faster than serving from disk?

You should read this:

http://varnish.projects.linpro.no/wiki/ArchitectNotes

It offers a good explanation of why trying to cache files in memory
(beyond what the OS already does) is usually counterproductive.

Cliff


--
http://www.google.com/search?q=vonage+sucks
Re: cache static content in memory
May 29, 2009 12:47PM
Thank you for your explanations.

Now, using proxy_cache_* am I able to cache only some pages?

Example:
site.com/
site.com/products/
site.com/products/cars/
site.com/products/cars/ferrari.php :)

How can I cache only "site.com/" and "site.com/products/"?

Thanks

N
Re: cache static content in memory
May 29, 2009 01:17PM
On Fri, May 29, 2009 at 12:47:03PM -0400, nfn wrote:

> Thank you for your explanations.
>
> Now, using proxy_cache_* am I able to cache only some pages?
>
> Example:
> site.com/
> site.com/products/
> site.com/products/cars/
> site.com/products/cars/ferrari.php :)
>
> How can I cache only "site.com/" and "site.com/products/"?

location / {
proxy_cache zone;
...
}

location /products/ {
proxy_cache zone;
...
}

location /products/cars/ {
proxy_cache off; # default
...
}


--
Igor Sysoev
http://sysoev.ru/en/
Re: cache static content in memory
May 29, 2009 02:06PM
Ok ..

Thanks Igor :)

So, If I have a "site.com/contact/" it will be cached since we have:

location / {
proxy_cache zone;
...
}

To avoid this I need to add:

location /contact/ {
proxy_cache off; # default
...
}

Is that it?
Re: cache static content in memory
May 29, 2009 02:37PM
On Fri, May 29, 2009 at 02:06:28PM -0400, nfn wrote:

> Ok ..
>
> Thanks Igor :)
>
> So, If I have a "site.com/contact/" it will be cached since we have:
>
> location / {
> proxy_cache zone;
> ...
> }
>
> To avoid this I need to add:
>
> location /contact/ {
> proxy_cache off; # default
> ...
> }
>
> Is that it?

If you set

location / {
proxy_cache zone;
...
}

location /contact/ {
...
}

then /contact wil not be cached.


--
Igor Sysoev
http://sysoev.ru/en/
Re: cache static content in memory
May 29, 2009 04:05PM
Thank you Igor,

Maybe a suggestion (I don't know nginx fully) ... have a regular expression implementation to cache functions.

Thanks

N
Re: cache static content in memory
May 30, 2009 02:52AM
On Fri, May 29, 2009 at 04:05:58PM -0400, nfn wrote:

> Thank you Igor,
>
> Maybe a suggestion (I don't know nginx fully) ... have a regular expression implementation to cache functions.

http://wiki.nginx.org/NginxHttpCoreModule#location


--
Igor Sysoev
http://sysoev.ru/en/
Re: cache static content in memory
May 30, 2009 09:48AM
Thank you Igor. I already know that.

I was think about something like this just to proxy_cache & fastcgi_cache:

location / {
proxy_cache zone;
...
proxy_cache_match ^~ /products/;
proxy_cache_match ^~ /catalog/;
...
}



Edited 1 time(s). Last edit at 05/30/2009 09:49AM by nfn.
Re: cache static content in memory
May 30, 2009 03:20PM
On Sat, May 30, 2009 at 09:48:01AM -0400, nfn wrote:

> Thank you Igor. I already know that.
>
> I was think about something like this just to proxy_cache & fastcgi_cache:
>
> location / {
> proxy_cache zone;
> ...
> proxy_match ^~ /products/;
> proxy_match ^~ /catalog/;
> ...
> }

I do not understand semantics of this.


--
Igor Sysoev
http://sysoev.ru/en/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 61
Record Number of Users: 8 on December 02, 2009
Record Number of Guests: 129 on December 15, 2009
Powered by nginx    Powered by FreeBSD    PHP Powered    Powered by MySQL