开发者

Client side caching using Apache 2

I have a script that is consumming too much resource to provide开发者_开发问答 data that could be retrieved only each minute. Is there a way to configure Apache 2 through an .htaccess file to specify headers telling to the client to keep the script result as is for one minute in its cache ?

I know this could be done through the script itself, but I would like to do this through the webserver's configuration.


mod_expires is the good solution.

If you are on a unix-like system :

a2enmod expires
apache2ctl restart

Then you will be able to define the expiration conditions for a given file, or define the cache policy according to mimetype through your .htaccess file.

<IfModule mod_expires.c>
    ExpiresActive On

    ExpiresByType image/gif A3600

    <Files scriptToCache.php>
        ExpiresDefault A60
    </Files>
</IfModule>

Here "A3600" means that the file expires 3600 seconds after access.

More information here : http://httpd.apache.org/docs/2.0/mod/mod_expires.html


Short answer is no - you need to return the caching headers from the script.


<IfModule mod_expires.c>
          <FilesMatch "\.(jpe?g|png|gif|js|css)$">
                      ExpiresActive On
                      ExpiresDefault "access plus 1 year"
          </FilesMatch>
</IfModule>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜