Re: [fw-general] How to generate a good cache identifier based on URL?
Wait, md5() doesn't generate a globally unique identifier, right? So then you could still have the same problem? Peter On 8/31/07, Steven Brown [EMAIL PROTECTED] wrote: Good one! -Original Message- From: Federico Galassi [mailto:[EMAIL PROTECTED] On Behalf Of Federico Galassi Sent: Friday, 31 August 2007 9:50 PM To: Peter Van Dijck Cc: fw-general@lists.zend.com Subject: Re: [fw-general] How to generate a good cache identifier based on URL? On 31/ago/07, at 10:17:51, Peter Van Dijck wrote: Any thoughts on how to improve this would be very welcome :) $cache_identifier = md5($_SERVER['REQUEST_URI']); Federico -- 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
Re: [fw-general] How to generate a good cache identifier based on URL?
On 01/set/07, at 09:03:37, Peter Van Dijck wrote: Wait, md5() doesn't generate a globally unique identifier, right? So then you could still have the same problem? Theoretically yes, for all your practical purposes no. The number of possible output strings (hashes) produced by md5() is so big that every input is paired to a virtually unique hash. Federico
Re: [fw-general] How to generate a good cache identifier based on URL?
Peter Van Dijck schrieb: 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']); Here you replace / with _ from REQUEST_URI $cache_identifier = ereg_replace(., _, $_SERVER['REQUEST_URI']); Here you replace . with _ also from REQUEST_URI and overwrite the cache_identifier. The line before has no effect. $cache_identifier = preg_replace(/([^a-zA-Z0-9_-])/, '', $cache_identifier); Here you remove all non-allowed characters. This includes /, which is not replaced because the first replacement take no part. Also replacement with nothing is not such a good idea, because maybe youre missing an important seperator. Its better you replace with a character instead. I think, you should dump both the wrong-cached- and the real-page-identifier and compare them. 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
RE: [fw-general] How to generate a good cache identifier based on URL?
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: fw-general@lists.zend.com 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
Re: [fw-general] How to generate a good cache identifier based on URL?
On 31/ago/07, at 10:17:51, Peter Van Dijck wrote: Any thoughts on how to improve this would be very welcome :) $cache_identifier = md5($_SERVER['REQUEST_URI']); Federico
RE: [fw-general] How to generate a good cache identifier based on URL?
Good one! -Original Message- From: Federico Galassi [mailto:[EMAIL PROTECTED] On Behalf Of Federico Galassi Sent: Friday, 31 August 2007 9:50 PM To: Peter Van Dijck Cc: fw-general@lists.zend.com Subject: Re: [fw-general] How to generate a good cache identifier based on URL? On 31/ago/07, at 10:17:51, Peter Van Dijck wrote: Any thoughts on how to improve this would be very welcome :) $cache_identifier = md5($_SERVER['REQUEST_URI']); Federico
Re: [fw-general] How to generate a good cache identifier based on URL?
I would point out that it's a _bad_ design to have Zend_Cache_Core make this assertion. This restriction makes it impossible to interoperate the cache with other systems that don't have a similar restriction on ID space. It would be better if this was left to the Backend implementation to validate, potentially via a Backend-_validateIdOrTag(...). --koblas Peter Van Dijck wrote: 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