Cache based on file size

Hi,

In looking over Nginx configuration for the proxy module, I do not see
an easy way to influence what is cached based on object size. I have two
use cases of interest:

  1. Store a small file in a particular zone (e.g., SSD), and

  2. Have a large file bypass the cache (no-store large files)

Any insight on how best to accomplish this would be greatly appreciated.

Kevin

Hello!

On Mon, Aug 05, 2013 at 10:28:31PM +0000, Johns, Kevin wrote:

Hi,

In looking over Nginx configuration for the proxy module, I do not see an easy
way to influence what is cached based on object size. I have two use cases of
interest:

  1. Store a small file in a particular zone (e.g., SSD), and

  2. Have a large file bypass the cache (no-store large files)

Any insight on how best to accomplish this would be greatly appreciated.

The proxy_no_cache with appropriate variables (e.g., map’ed or
produced with embedded perl from $upstream_http_content_length)
might be usable.

E.g. the following should disable caching of responses larger than
999 bytes or with content length not known:

map $upstream_http_content_length $toolarge {
    default    1;
    ~^\d\d\d$  0;
}

proxy_no_cache $toolarge;

(Untested.)

See http://nginx.org/r/proxy_no_cache for details.


Maxim D.
http://nginx.org/en/donation.html