Issues

ZF-208: Ability to take cache identifier as any string

Description

As requested from Mislav to open this ticket. Ability to set identifier as any kind of string and not just "'Invalid id or tag : must use only [a-zA-A0-9_]'"

e.g.


$urlToSomeData = "http://api.example.com/give/me/cars/from/new_york/?sort=year";

if($data  = $cache->get($urlToSomeData)){
    //......
}else{
    $data = file_get_contents($urlToSomeData);
//.......
    $cache->save($data);
}

I would recommend some fast hashing function on the identifier string, which will produce file name, if this will not corrupt current Cache system.

Comments

We have to take some time to think about that.

Because from my point of view, the md5() should be done by the user in such cases and not by Zend_Cache.

Let's take some time to consider this issue.

The issue here is to decide how much would we allow to be a cache identifier. I think it's not right for a backend to limit us (like filesystem did). On the other hand, allowing everything would be expensive and maybe we'd have too much trouble with our backends

I was thinking about implementing it for myself in a plugin with something along the lines of:


$identifier = preg_replace('#[^a-zA-Z0-9_]#', '_', $identifier) . '_' . abs(crc32($identifier));

I was under the impression that crc32 was a fast hashing algorithm, but I don't know how expensive this operation would be. Or how useful the crc32 is...

Whatever the solution, perhaps the ability to have all characters in an identifier should be a configurable option, per Zend_Cache object?

After taking some time, I think that the cache identifier must be a string.

If someone want to use a "not string" identifier, it's not difficult to call md5(serialize($yourId)) before calling Zend_Cache.

Let's keep "hacks" out of Zend_Cache.

So I close this task