Re: Caching via URL

From: Manuel Lemos (mlemos_at_acm.org)
Date: 03/05/04


Date: Thu, 04 Mar 2004 21:23:03 -0300

On 03/04/2004 04:25 AM, Shabam wrote:
> I need to implement a caching mechanism for my script URLs. Instead of
> www.domain.com/script.cgi?id=1234 , which the browser will obviously not
> cache, I want the URL to be something like www.domain.com/1234 or
> www.domain.com/1234.htm instead. This way the browser will cache the page.

I am afraid there is some misconception here. Client side caching has
nothing to do with the scripts page URL but rather with the headers the
scripts return.

> I have two concerns:
>
> 1) Is this possible without rewriting the url? If so how?

With PHP and Apache yes. You can have a script named browse . Configure
Apache to handle it as PHP script. Then use URLs like browse/1234.html .
There by looking at some of the request variables you can extract the
1234 from de /browse/1234.html REQUEST_URI .

> 2) The result page will be different for different users. Will this cause
> trouble with proxy servers? My goal is only to cache a particular version
> for a particular user so that if he requests the URL again (within X
> minutes) the server doesn't have to process it again.

I am afraid you can't do that with client side caching precisely because
of proxy servers.

You can improve things via server side caching. I use this class that
can produce different caches with distinct timeouts for different types
of users. It stores cached content on files as well timeout values. You
just need to use different cache file names for the different types of
users so it can check the correct cached version.

I use this all the time to cache different page versions for different
groups of users (anononymous, logged in, administrators, authors, etc..).

http://www.phpclasses.org/filecache

-- 
Regards,
Manuel Lemos
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/
Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html


Relevant Pages

  • Re: [PHP] Aggressive PHP Smart Caching
    ... i have begun to experiment w/ your caching tool. ... it is also important that the script calling ob_end_flushhave access to ... the header method in the first bit of code in the cache tool. ...
    (php.general)
  • Re: include_once() within a function
    ... > used by the script, so instead of using include or include_once in the ... static $cache; ... Just declaring them static with no check wether they are allready set would not have the desired effect. ...
    (comp.lang.php)
  • Re: [PHP] Aggressive PHP Smart Caching
    ... If it weren't for the fact that this method, as I have designed it, allows a very tiny PHP overhead to handle dynamic updating of the cache I could have even gone the extra mile to push html files that would be loaded directly by the end user without PHP being initialized at all. ... Caching on disk could easily be handled instead by caching in memory, but this approach is meant to be ultra-portable and work everywhere. ... In order to not rely on cron, server queries, or other external checks for a stale cache, I have gone with a "refresh interval" which has been proposed on this list in the past. ... This script avoids PHP date manipulations and instead performs some basic math to handle the refresh rate, but also to *sync* content to some degree, so portions of dynamic content are less likely to haphazardly refresh independently and therefore not match. ...
    (php.general)
  • Re: ]OT] http-authorization:
    ... script loading perl on every hit it will be slower. ... use PHP and other scripting languages in very naive ways with the nearly inevitable result of tanking the backend database under load. ... Frequently the people writing the scripts have no formal training in programming and so have no idea about such basic concepts as caching, ... That site is nearly entirely Java and mod_perl under the hood. ...
    (Fedora)
  • Re: include_once() within a function
    ... used by the script, so instead of using include or include_once in the ... static $cache; ... Just declaring them static with no check wether they are allready set ...
    (comp.lang.php)