# S-maxage not being honored with proxy\_cache

**URL:** <https://www.ruby-forum.com/t/s-maxage-not-being-honored-with-proxy-cache/228469>\
**Category:** NGINX\
**Created:** [April 23, 2013, 5:06pm UTC](https://www.ruby-forum.com/t/s-maxage-not-being-honored-with-proxy-cache/228469 "2013-04-23T17:06:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_P.ish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@Ryan\_P.ish](https://www.ruby-forum.com/u/Ryan_P.ish)\
**Post date:** [April 23, 2013, 5:06pm UTC](https://www.ruby-forum.com/t/s-maxage-not-being-honored-with-proxy-cache/228469/1 "2013-04-23T17:06:24Z")

</div>

I have a slow backend application that I’m using nginx to provide  
the authentication and caching for. It’s been working great however  
there  
is one nagging issue that I cannot seem to resolve, when the backend app  
sets a s-maxage and a maxage Cache-Control, nginx only seems to honor  
the  
maxage and expires the cache with its value.

An example response from the backend is like this…

Cache-Control: max-age=60, s-maxage=3600, public, must-revalidate  
My idea here is I only want the client to cache this data for a short  
amount of time before checking in with me it see if it’s still valid.  
The  
data usually wont be changing that often so I want nginx to cache it for  
an  
hour, but in the event it does I use the excellent nginx-cache-purge  
script  
in my backend app to invalidate the cache and the next time a client  
checks  
in (after 60 seconds) they will get the new data.

However in all my testing and usage I will only get a cache HIT for 60  
seconds after the first request to a resource, after 60 seconds it will  
be  
EXPIRED then it will go to the backend again. Am I missing something in  
the Cache-Control that is causing this behavior?

–

Ryan P.ish

---

<div class="post-metadata">

**Author:** ![Ryan\_P.ish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@Ryan\_P.ish](https://www.ruby-forum.com/u/Ryan_P.ish)\
**Post date:** [April 24, 2013, 1:42pm UTC](https://www.ruby-forum.com/t/s-maxage-not-being-honored-with-proxy-cache/228469/2 "2013-04-24T13:42:32Z")

</div>

Hello!

On Tue, Apr 23, 2013 at 11:05:58AM -0400, Ryan P.ish wrote:

> amount of time before checking in with me it see if it’s still valid. The  
> data usually wont be changing that often so I want nginx to cache it for an  
> hour, but in the event it does I use the excellent nginx-cache-purge script  
> in my backend app to invalidate the cache and the next time a client checks  
> in (after 60 seconds) they will get the new data.

Note: you will not be able to purge shared chaches outside of your  
control, so this might not work as you expect.

> However in all my testing and usage I will only get a cache HIT for 60  
> seconds after the first request to a resource, after 60 seconds it will be  
> EXPIRED then it will go to the backend again. Am I missing something in  
> the Cache-Control that is causing this behavior?

As of now nginx doesn’t handle s-maxage.

Trivial solution is to use X-Accel-Expires to specifi expiration  
time for your nginx cache. This should also better match a use  
case you’ve described (as it will only ask your nginx cache to  
cache longer, not all shared caches in the world).

–  
Maxim D.

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

---

<div class="post-metadata">

**Author:** ![Ryan\_P.ish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@Ryan\_P.ish](https://www.ruby-forum.com/u/Ryan_P.ish)\
**Post date:** [April 24, 2013, 3:52pm UTC](https://www.ruby-forum.com/t/s-maxage-not-being-honored-with-proxy-cache/228469/3 "2013-04-24T15:52:13Z")

</div>

On Wed, Apr 24, 2013 at 7:41 AM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > in my backend app to invalidate the cache and the next time a client  
> > the Cache-Control that is causing this behavior?
> 
> As of now nginx doesn’t handle s-maxage.
> 
> Trivial solution is to use X-Accel-Expires to specifi expiration  
> time for your nginx cache. This should also better match a use  
> case you’ve described (as it will only ask your nginx cache to  
> cache longer, not all shared caches in the world).

That worked perfectly, thank you!

–

–

Ryan P.ish  
Chief Technologist, Member  
CoreLogic LLC  
M: (408)966-4673

> **[CoreLogic LLC | Solutions For The Extended Enterprise](http://www.corelogicllc.com)**

solutions for the extended enterprise
