You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Jergen Dutch <je...@gmail.com> on 2007/12/07 10:16:29 UTC

[users@httpd] Intelligent/automatic cache expiry based on mtime

Hi list,

I have an application that loads a lot of images off a server every 60
seconds. I want the client's browser to cache the images because they almost
never change.

In the rare cases where an image does change, I would like to invalidate the
client's cached copy of the image.

I could do this with a script, but it seems such a simple and generic thing
that Apache must surely already provide this (I can't find it though).

Can I add a cache-invalidation header for .jpg files modified in the past
120 seconds?

Thanks.

RE: [users@httpd] Intelligent/automatic cache expiry based on mtime

Posted by Axel-Stephane SMORGRAV <Ax...@europe.adp.com>.
I guess that depends on what you want to achieve.

The Expires header indicates the time at which the resource expires. This means that until the expiry date, a cache may serve the resource without revalidating it, i.e. sending a conditional request to ask if there would happen to be a newer version available. That allows you to force a revalidation of the resource ever so often.

During the revalidation, if the resource in cache is fresh, the server will reply with a HTTP 304 "Not Modified".

Assume now that you have a response with a Last-Modified and an E-Tag, but no Expires or max-age. How often will the client do conditional requests to verify whether there is a newer version available? My guess is that it will apply heuristic expiration, which is pretty much up to each client implementation, i.e. undefined. That means you will never know how long it will take from the time you change the image until the image has actually been loaded by a client.

Not only that but heuristic expiration is a function of the age of the resource (depends on Last-Modified). In the beginning it will expire frequently, and then progressively less frequently.

Expires and max-age allow you to force revalidation at regular, known intervals. You original questions was:

>Can I add a cache-invalidation header for .jpg files modified in the past 120 seconds? 

AFAIK that can only be achieved by forcing revalidation after 120 seconds...

-ascs
 
-----Message d'origine-----
De : Jergen Dutch [mailto:jergendutch@gmail.com] 
Envoyé : mardi 11 décembre 2007 14:00
À : users@httpd.apache.org
Objet : Re: [users@httpd] Intelligent/automatic cache expiry based on mtime

On Dec 7, 2007 2:29 PM, Axel-Stephane  SMORGRAV <Ax...@europe.adp.com> wrote:
> ExpiresByType image/jpeg "modification plus 120 seconds"

This will expire images which have not changed.
I will stiick with etags.

Thanks.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Intelligent/automatic cache expiry based on mtime

Posted by Jergen Dutch <je...@gmail.com>.
On Dec 7, 2007 2:29 PM, Axel-Stephane  SMORGRAV
<Ax...@europe.adp.com> wrote:
> ExpiresByType image/jpeg "modification plus 120 seconds"

This will expire images which have not changed.
I will stiick with etags.

Thanks.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Intelligent/automatic cache expiry based on mtime

Posted by Axel-Stephane SMORGRAV <Ax...@europe.adp.com>.
ExpiresByType image/jpeg "modification plus 120 seconds"


-ascs
 
-----Message d'origine-----
De : Jergen Dutch [mailto:jergendutch@gmail.com] 
Envoyé : vendredi 7 décembre 2007 13:02
À : users@httpd.apache.org
Objet : Re: [users@httpd] Intelligent/automatic cache expiry based on mtime

On Dec 7, 2007 11:25 AM, Axel-Stephane  SMORGRAV <Ax...@europe.adp.com> wrote:
> Sorry for being crude, but why don't you just read the manual (mod_expires) ??
>
> ExpiresByType image/jpeg "modification plus 1 day"

Because this is doing something different to what I want.
Your suggestion would expire content a day after the mtime. See my original message.

> I cannot recall that RFC2616 specifies exactly how the e-tag is computed, so I do not think that you can assume that the modification date will necessarily be part of the e-tag computation.

The documentation says mtime is included in calculating the etag by default in apache.

>
> -ascs

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Intelligent/automatic cache expiry based on mtime

Posted by Jergen Dutch <je...@gmail.com>.
On Dec 7, 2007 11:25 AM, Axel-Stephane  SMORGRAV
<Ax...@europe.adp.com> wrote:
> Sorry for being crude, but why don't you just read the manual (mod_expires) ??
>
> ExpiresByType image/jpeg "modification plus 1 day"

Because this is doing something different to what I want.
Your suggestion would expire content a day after the mtime. See my
original message.

> I cannot recall that RFC2616 specifies exactly how the e-tag is computed, so I do not think that you can assume that the modification date will necessarily be part of the e-tag computation.

The documentation says mtime is included in calculating the etag by
default in apache.

>
> -ascs

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] Intelligent/automatic cache expiry based on mtime

Posted by Axel-Stephane SMORGRAV <Ax...@europe.adp.com>.
Sorry for being crude, but why don't you just read the manual (mod_expires) ?? 

ExpiresByType image/jpeg "modification plus 1 day"

I cannot recall that RFC2616 specifies exactly how the e-tag is computed, so I do not think that you can assume that the modification date will necessarily be part of the e-tag computation.

-ascs
 
-----Message d'origine-----
De : Jergen Dutch [mailto:jergendutch@gmail.com] 
Envoyé : vendredi 7 décembre 2007 11:18
À : users@httpd.apache.org
Objet : Re: [users@httpd] Intelligent/automatic cache expiry based on mtime

On Dec 7, 2007 11:01 AM, C.F-Win in China F <we...@gmail.com> wrote:

> ExpiresByType image/jpeg "access plus 1 day"
>

Thanks for this, but I don't want to expire the cache based on access, I want to expire the cache based on mtime.

etags should handle this, but it seems not too..

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Intelligent/automatic cache expiry based on mtime

Posted by Jergen Dutch <je...@gmail.com>.
On Dec 7, 2007 11:01 AM, C.F-Win in China F <we...@gmail.com> wrote:

> ExpiresByType image/jpeg "access plus 1 day"
>

Thanks for this, but I don't want to expire the cache based on access,
I want to expire the cache based on mtime.

etags should handle this, but it seems not too..

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Intelligent/automatic cache expiry based on mtime

Posted by "C.F-Win in China F" <we...@gmail.com>.
ExpiresByType image/jpeg "access plus 1 day"