# Proxy\_cache\_valid for zero seconds

**URL:** <https://www.ruby-forum.com/t/proxy-cache-valid-for-zero-seconds/224521>\
**Category:** NGINX\
**Created:** [November 14, 2012, 10:10pm UTC](https://www.ruby-forum.com/t/proxy-cache-valid-for-zero-seconds/224521 "2012-11-14T22:10:22Z")\
**Posts on this page:** 2\
**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:** [November 14, 2012, 10:10pm UTC](https://www.ruby-forum.com/t/proxy-cache-valid-for-zero-seconds/224521/1 "2012-11-14T22:10:22Z")

</div>

Greetings,

I am trying to configure nginx proxy\_cache so that it stores a cached  
copy  
of a HTTP response, but serves from cache _only_ under the conditions  
defined by proxy\_cache\_use\_stale.

I have tried something like this without success:

```
proxy_cache_valid 200 204 301 302 0s;
proxy_cache_use_stale error timeout updating invalid_header

```

http\_500 http\_502 http\_504;

“0s” appears to avoid caching completely. “1s” stores a cached copy,  
but  
presumably serves from cache for one second. I am trying to serve from  
cache only when the upstream errs.

Thank you

Posted at Nginx Forum:

> **[proxy\_cache\_valid for zero seconds](https://forum.nginx.org/read.php?2,232815,232815#msg-232815)**
>
> Greetings, I am trying to configure nginx proxy\_cache so that it stores a cached copy of a HTTP response, but serves from cache \*only\* under the conditions defined by proxy\_cache\_use\_stale. I have tried something like this without success:...

---

<div class="post-metadata">

**Author:** ![shmapty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@shmapty](https://www.ruby-forum.com/u/shmapty)\
**Post date:** [November 20, 2012, 9:12pm UTC](https://www.ruby-forum.com/t/proxy-cache-valid-for-zero-seconds/224521/2 "2012-11-20T21:12:29Z")

</div>

Put another way – can I store/cache all content from the proxied  
upstream  
(up to the limits defined in proxy\_cache\_path), but serve from the cache  
only when the proxied upstream fails (e.g. timeout, error)?

We have content that should be dynamic, and hence every request should  
be  
transparently proxied. However, I want to protect against the situation  
when the upstream is down or having trouble. Serving a stale response  
(though normally undesirable), is better than returning an error.

Thank you

Posted at Nginx Forum:

> **[Re: proxy\_cache\_valid for zero seconds](https://forum.nginx.org/read.php?2,232815,233027#msg-233027)**
>
> Greetings, I am trying to configure nginx proxy\_cache so that it stores a cached copy of a HTTP response, but serves from cache \*only\* under the conditions defined by proxy\_cache\_use\_stale. I have tried something like this without success:...
