Re: Cache_Lite Bug on Resave?
| From: | Michael | Date: | Thu, 20 Feb 2003 13:20:08 +0000 |
| Subject: | Re: Cache_Lite Bug on Resave? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-3858@lists.php.net to get a copy of this message | ||
I found the problem. On line 337:
$length = @filesize($this->_file);
The filesize is cached, resulting in an incorrect read when saving after a successful get. Perhaps a flag would be in order that tracks if a successful get has been performed. Following a successful get, a save should clearstatcache() before performing a filesize()
That or the user should be responsible for doing a clearstatcache(); before calling save (probably not as preferable).
Michael
Michael wrote:
Hi, I seem to be running into some trouble with Cache_Lite upon resaving data for caching. The below script demonstrates the problem. I am using Cache_lite with read and write checking. ---------------- if ($data = $cache->get('test')) {var_dump($data = unserialize($data)); // Success $data->now(); $cache->save(serialize($data), 'test'); // Failure} else {$data = new test(); $cache->save(serialize($data), 'test'); // Success} class test {var $now = null; var $then = null;function test() { $this->then = time(); }function now() { $this->now = time(); }} ----------------- For some reason that is totally escaping me, when doing the read control, it fails: line 341:$hashControl = " -155960464"//Correct line 344: $data = @fread($fp, $length); // Incorrect, it only reads in a incomplete amount of the data $data = "O:4:"test":2:{s:3:"now";i:1045743845;s:4:"then";i:1"; // It should be $data_in_reality = "O:4:"test":2:{s:3:"now";i:1045743845;s:4:"then";i:1045743833;}"; // And hashData is incorrectly evaluated to$hashData = " -1334859930"What puzzles me is that when doing the initial $cache->save(), it works absolutely fine. Why is it that my recaching fails? Thanks, Michael