# Proxy cache max size

**URL:** <https://www.ruby-forum.com/t/proxy-cache-max-size/221077>\
**Category:** NGINX\
**Created:** [June 29, 2012, 3:29pm UTC](https://www.ruby-forum.com/t/proxy-cache-max-size/221077 "2012-06-29T15:29:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 29, 2012, 3:29pm UTC](https://www.ruby-forum.com/t/proxy-cache-max-size/221077/1 "2012-06-29T15:29:01Z")

</div>

I have a question. If the file being written to a cache exceeds max size  
what behavior happens? As I can think of it there are 3 possible  
outcomes.

1. File is written and later cleaned up by the cache manager (bad)
2. File isnt written. It is recognized that it can’t be cached.
3. The file is written and truncated (bad)

Thanks

Sent from my iPad

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 29, 2012, 3:56pm UTC](https://www.ruby-forum.com/t/proxy-cache-max-size/221077/2 "2012-06-29T15:56:29Z")

</div>

Hello!

On Fri, Jun 29, 2012 at 11:28:08PM +1000, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a question. If the file being written to a cache exceeds max size what  
> behavior happens? As I can think of it there are 3 possible outcomes.
> 
> 1. File is written and later cleaned up by the cache manager (bad)
> 2. File isnt written. It is recognized that it can’t be cached.
> 3. The file is written and truncated (bad)
> 
> Thanks

The file is written, and later cleaned up by the cache manager.

It might even be used for a while to serve requests, as it takes  
some time (up to 10 seconds) for the cache manager to recognize  
the max\_size limit was exceeded and least recently used files  
should be removed from the cache.

Maxim D.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 30, 2012, 9:21am UTC](https://www.ruby-forum.com/t/proxy-cache-max-size/221077/3 "2012-06-30T09:21:13Z")

</div>

Hmm this presents a rather large issue for me.

Is it possible to get the upstream response size in lua and set a  
variable  
to influence proxy\_no\_cache? If it is ill learn lua.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 30, 2012, 6:11pm UTC](https://www.ruby-forum.com/t/proxy-cache-max-size/221077/4 "2012-06-30T18:11:43Z")

</div>

On Jun 30, 2012, at 3:20 AM, SplitIce wrote:

> Hmm this presents a rather large issue for me.
> 
> Is it possible to get the upstream response size in lua and set a variable to  
> influence proxy\_no\_cache? If it is ill learn lua.

By the time Lua gets involved, the response has already been cached (or  
not).

You could do your own cache instead of proxy\_cache, of course. I have  
some things that store the “cache” in redis, for example. Could be  
memcache, custom cache, etc.

–Brian

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 1, 2012, 6:57pm UTC](https://www.ruby-forum.com/t/proxy-cache-max-size/221077/5 "2012-07-01T18:57:05Z")

</div>

I came up with a crude solution, proxy\_max\_temp\_file\_size. By limiting  
the  
max size in cached paths to 50mb I should make it impossible for someone  
to  
store GBs of data to the disk before the cache manager runs.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 2, 2012, 11:04am UTC](https://www.ruby-forum.com/t/proxy-cache-max-size/221077/6 "2012-07-02T11:04:38Z")

</div>

Hello!

On Mon, Jul 02, 2012 at 02:56:47AM +1000, SplitIce wrote:

> I came up with a crude solution, proxy\_max\_temp\_file\_size. By limiting the  
> max size in cached paths to 50mb I should make it impossible for someone to  
> store GBs of data to the disk before the cache manager runs.

No, the proxy\_max\_temp\_file\_size directive is ignored if cache is  
used. This is for reason, as common use case is to disable disk  
buffering with “proxy\_max\_temp\_file\_size 0;”, but have cache  
switched on for some requests.

Maxim D.

> > > Is it possible to get the upstream response size in lua and set a
> > 
> > * * *
> > 
> > nginx mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)
