# Try\_files based on file mtime?

**URL:** <https://www.ruby-forum.com/t/try-files-based-on-file-mtime/190058>\
**Category:** NGINX\
**Created:** [June 12, 2010, 6:20am UTC](https://www.ruby-forum.com/t/try-files-based-on-file-mtime/190058 "2010-06-12T06:20:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stdragon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@stdragon](https://www.ruby-forum.com/u/stdragon)\
**Post date:** [June 12, 2010, 6:20am UTC](https://www.ruby-forum.com/t/try-files-based-on-file-mtime/190058/1 "2010-06-12T06:20:46Z")

</div>

Hi all,

I found nginx a little while ago and I’ve been working on a fast  
wordpress setup with it. One thing I’m having a problem with is serving  
cached pages with an expiration.

So I have this (simplified a bit):

```
    location / {
            # If it's a real static file just serve it, otherwise 

```

check the cache  
try\_files $uri $uri/ @checksupercache;  
}

```
    location @checksupercache {
            # First check if user is logged in, etc, but let's 

```

assume not, so we want to serve the static cache if it exists  
# This is the point where I would like to check the  
file’s mtime. If it’s too old, use @gotoblog even though the file  
exists.  
try\_files  
/wp-content/cache/supercache/$http\_host/$uri/index.html @gotoblog;  
}

How do I implement that last part? Say I want cached pages to last 2  
minutes. Something like this would be perfect:  
try\_files 2m blah/blah/$uri @otherwise;

What’s the best way to do this?

If there’s not a great way right now, would this be better/easier for me  
to implement as a patch to try\_files or as a separate module with a  
separate command?

Thanks!

Posted at Nginx Forum:

> **[try\_files based on file mtime?](https://forum.nginx.org/read.php?2,97433,97433#msg-97433)**
>
> Hi all, I found nginx a little while ago and I've been working on a fast wordpress setup with it. One thing I'm having a problem with is serving cached pages with an expiration. So I have this (simplified a bit): location / {

---

<div class="post-metadata">

**Author:** ![stdragon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@stdragon](https://www.ruby-forum.com/u/stdragon)\
**Post date:** [June 12, 2010, 9:47am UTC](https://www.ruby-forum.com/t/try-files-based-on-file-mtime/190058/2 "2010-06-12T09:47:56Z")

</div>

On Sat, Jun 12, 2010 at 12:19:16AM -0400, stdragon wrote:

> If there’s not a great way right now, would this be better/easier for me to implement as a patch to try\_files or as a separate module with a separate command?

Why not use the proxy/fastcgi cache ?

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![stdragon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@stdragon](https://www.ruby-forum.com/u/stdragon)\
**Post date:** [June 12, 2010, 4:23pm UTC](https://www.ruby-forum.com/t/try-files-based-on-file-mtime/190058/3 "2010-06-12T16:23:33Z")

</div>

## Igor S. Wrote:

> > If there’s not a great way right now, would this  
> > be better/easier for me to implement as a patch to  
> > try\_files or as a separate module with a separate  
> > command?
> 
> Why not use the proxy/fastcgi cache ?

I thought about doing that first, but it seems difficult to let php  
control the cache, like deleting specific files or clearing the entire  
cache when certain events happen.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,97433,97508#msg-97508](http://forum.nginx.org/read.php?2,97433,97508#msg-97508)

---

<div class="post-metadata">

**Author:** ![stdragon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@stdragon](https://www.ruby-forum.com/u/stdragon)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/try-files-based-on-file-mtime/190058/4 "2010-06-17T16:22:05Z")

</div>

stdragon ha scritto:

> > > What’s the best way to do this?

What about proxy/fastcgi store, instead?

Stored response from backend are saved to well know files, so you have  
full control over them.

It’s not a cache, however.

Regards

---

<div class="post-metadata">

**Author:** ![stdragon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@stdragon](https://www.ruby-forum.com/u/stdragon)\
**Post date:** [September 14, 2012, 11:16am UTC](https://www.ruby-forum.com/t/try-files-based-on-file-mtime/190058/5 "2012-09-14T11:16:25Z")

</div>

Hello stdragon,

I also need this function (try\_files based on file mtime). To you have a  
solution already?

Thank…

Regards  
wayan

Posted at Nginx Forum:

> **[Re: try\_files based on file mtime?](https://forum.nginx.org/read.php?2,97433,230721#msg-230721)**
>
> Hi all, I found nginx a little while ago and I've been working on a fast wordpress setup with it. One thing I'm having a problem with is serving cached pages with an expiration. So I have this (simplified a bit): location / {
