Here's what worked for me:

$cacheName = $_SERVER['REQUEST_URI'];
$cacheName = preg_replace('/[^a-zA-Z0-9]/', '__', $cacheName);

if(!($output = $cache->load($cacheName))) {

You need to strip out all the other junk because the cache identifier is
used in the file name. I used __ because the URI would likely have _ but not
__, and just stripping the junk out could cause two different URIs to be the
same.

Also I was trying to use the Function cache frontend for accessing object
methods and had to build my own as the default one does not handle methods,
only functions (as far as I could tell).

-----Original Message-----
From: Peter Van Dijck [mailto:[EMAIL PROTECTED] 
Sent: Friday, 31 August 2007 6:18 PM
To: [email protected]
Subject: [fw-general] How to generate a good cache identifier based on URL?

Hi all,
I am using a caching identifier based on the URL. But I'm getting
strange effects: when accessing a URL I see the cached version of
*another* page.

This is the code I'm using for the cache identifier.

$cache_identifier = ereg_replace("/", "_", $_SERVER['REQUEST_URI']);
$cache_identifier = ereg_replace(".", "_", $_SERVER['REQUEST_URI']);
$cache_identifier = preg_replace("/([^a-zA-Z0-9_-])/", '',
$cache_identifier);

I added that last line because I was getting errors saying that the
cache identifier could only have a-z and _- characters.

Any thoughts on how to improve this would be very welcome :)

Thanks!
Peter

-- 
blog: http://poorbuthappy.com/ease/
work: http://petervandijck.com
free travel guides: http://poorbuthappy.com
US: (+1) 201 467-5511
Belgium: (+32) 03/325 88 70
Skype id: peterkevandijck

Reply via email to