Re: Cache

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Interesting idea. Using three identifiers, as a key.
md5() returns a 32 hex-digit value. That means that there are can only
be a maximum of 3.4 * 10^38 possible outcomes for the md5(). This
means that there there is a 1 in
340000000000000000000000000000000000000 chance of a collision between
filenames.

You could reduce those odds by a factor of three, by md5()ing each id
seperately, and concat'ing the resultant md5files. Alternatively
depending on your filesystem and the length of identifiers, you could
simply concat, and urlencode the  identifier. You could have a heck of
a long filename though.

I'd suggest taking a look at at the DB abstraction functions. They
were designed for what you're doing.

On 5/16/05, Evert | Rooftop <evert@xxxxxxxxxxxxxxxxxxx> wrote:
> Hi,
> 
> I'm developing a cache system. Which works in pseude code, like this:
> 
> class Cache {
> 
>   function Fetchdata($id1,$id2,$id3) {
> 
>     $id = md5($id1 . $id2 . $id3);
>     if ($this->DataIsExpired($id)) return false;
>    else return unserialize(file_get_contents($id));
> 
>  }
> 
>  function storeData($data,$id1,$id2,$id3) {
> 
>    $id = md5($id1 . $id2 . $id3);
>    OpenTheFileAndWriteTheDataSerialized($data);
>  }
> 
> }
> 
> $id1 $id2 and $id3 are when they are combined unique
> 
> * Is there a chance of collision when MD5 is used on the id's and the
> ids are long strings
> * Is file_get_contents the fastest way to open the file?
> * Is serialize the fastest way to serialize ;) ?
> * Are there any other things I should consider? (I'm aware of
> file-locking issues, and have taken care of that)
> 
> regards,
> Evert
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux