# Cache based on file size

**URL:** <https://www.ruby-forum.com/t/cache-based-on-file-size/236104>\
**Category:** NGINX\
**Created:** [August 6, 2013, 12:29am UTC](https://www.ruby-forum.com/t/cache-based-on-file-size/236104 "2013-08-06T00:29:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [August 6, 2013, 12:29am UTC](https://www.ruby-forum.com/t/cache-based-on-file-size/236104/1 "2013-08-06T00:29:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JohnsS\_Kevin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@JohnsS\_Kevin](https://www.ruby-forum.com/u/JohnsS_Kevin)\
**Post date:** [August 17, 2013, 2:54am UTC](https://www.ruby-forum.com/t/cache-based-on-file-size/236104/2 "2013-08-17T02:54:40Z")

</div>

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 [Module ngx\_http\_proxy\_module](http://nginx.org/r/proxy_no_cache) for details.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**
