Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.8.3

Request #13297 Support for per item lifetime
Submitted: 2008-03-03 19:39 UTC
From: brunobg Assigned:
Status: Open Package: Cache_Lite (version 1.7.2)
PHP Version: 5.2.2 OS: Linux
Roadmaps: 1.8    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 33 - 22 = ?

 
 [2008-03-03 19:39 UTC] brunobg (Bruno Barberi Gnecco)
Description: ------------ Cache_Lite supports changing the lifetime of an entry only globally, not per item. This patch provides an extension that allows the lifetime to be set per cache item. Test script: --------------- Provided in an attached file (.phpt) Expected result: ---------------- Provided in an attached file (.phpt) Actual result: -------------- Not a bug.

Comments

 [2009-01-27 12:27 UTC] damirr (Damir Ribaric)
Hi, We also encountered this problem and this is how we solved it: 1) current situation: - CacheLite ignores _lifeTime when saving data, it looks at the current _lifeTime when fetching data - when files are saved, the are saved with current timestamp and when data is fetched timestamp of the file is compared with current timestamp minus _lifeTime 2) our proposed change - when files are saved, they are saved with timestamp= current timestamp + _lifeTime (file timestamp is set to the future) - when files are fetched, file timestamp (which is previously set somewhere in the future) is compared with current timestamp - with that algorithm every item can have its lifetime and change to CacheLite is minimal and clear Here it is: Function Cache_Lite: _write is changed to: function _write($data) { if ($this->_hashedDirectoryLevel > 0) { $hash = md5($this->_fileName); $root = $this->_cacheDir; for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) { $root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/'; if (!(@is_dir($root))) { @mkdir($root, $this->_hashedDirectoryUmask); } } } $fp = @fopen($this->_file, "wb"); if ($fp) { if ($this->_fileLocking) @flock($fp, LOCK_EX); if ($this->_readControl) { @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); } $mqr = get_magic_quotes_runtime(); set_magic_quotes_runtime(0); @fwrite($fp, $data); set_magic_quotes_runtime($mqr); if ($this->_fileLocking) @flock($fp, LOCK_UN); @fclose($fp); // NEW LINE FIX – set file timestamp to the future! @touch( $this->_file, time() + abs($this->_lifeTime) ); return true; } return $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1); } Function Cache_Lite:_ _setRefreshTime is changed to: function _setRefreshTime() { if (is_null($this->_lifeTime)) { $this->_refreshTime = null; } else { $this->_refreshTime = time(); // not needed any more - $this->_lifeTime; } }