Re: Cache

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

 



Evert | Rooftop 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

Yes there is a chance, but it's small enough that for practical purposes you can ignore it.


* Is file_get_contents the fastest way to open the file?

AFAIK yes it is since it takes advantage of memory mapping (where possible).

* Is serialize the fastest way to serialize ;) ?

Not sure.

* Are there any other things I should consider? (I'm aware of file-locking issues, and have taken care of that)

regards,
Evert

Hmmmm... well, file_get_contents() doesn't lock the file so I'm interested in how you're accomplishing this feat. Perhaps you're creating a temporary directory (atomic IIRC) for the filename and then flocking that? I dunno, I hate race conditions.


You might also want to consider the security of the data that goes into your cache'd $_APP data. Because any file that is created by PHP is going to be in pretty much the same boat as the default session files and on a shared server, well...

--
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