Re: Cache patches
| From: | Alan Knowles | Date: | Sun, 09 Feb 2003 13:18:03 +0000 |
| Subject: | Re: Cache patches | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-13079@lists.php.net to get a copy of this message | ||
Peter, it's usually worth cc'ing the maintainers (although they are probably on the list..)
It's also worth checking the CS standards (I know they are annoying, but they are better than nothing :)
eg. if () {\n return; \n }\n
rather than if () \n return;\n
function xxx () \n {\n
rather than
function xxx () {\n
(although it looked like the original didnt do that.. - and I often get it wrong)
Regards
Alan
Peter Bowen wrote:
I have been using the two attached patches to the Cache module for several months in production without any problems. The first one, php-Cache-1.5.1-none-encoding.patch corrects the documentation for the encoding_mode property and adds a 'none' option for situations where base64 encoding is unnecessary. Using none significantly speeds up the cache. The second patch, php-Cache-1.5.1-getexprires.patch, adds an API method to get the expiration date of the cache entry and uses it where appropriate. It is useful when acaching full HTTP content responses as it allows the Expires header to be set accurately. I hope that other people find these useful and they can get merged into CVS. Thanks. Peter ------------------------------------------------------------------------ Index: Cache.php =================================================================== RCS file: /repository/pear/Cache/Cache.php,v retrieving revision 1.4 diff -u -r1.4 Cache.php --- Cache.php 12 Jul 2002 17:30:57 -0000 1.4 +++ Cache.php 1 Aug 2002 19:55:11 -0000 @@ -249,6 +250,21 @@-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.comreturn $this->container->getUserdata($id, $group); } // end func getUserdata++ /** + * Returns the exiration date of a cached data set. + * + * @param string dataset ID + * @param string cache group + * @return integer exiration date + * @access public + */ + function getExpires($id, $group = 'default') { + if (!$this->caching) + return -1;++ return $this->container->getExpires($id, $group); + } // end func getExpires /** * Removes the specified dataset from the cache.Index: Container.php =================================================================== RCS file: /repository/pear/Cache/Container.php,v retrieving revision 1.3 diff -u -r1.3 Container.php --- Container.php 12 Jul 2002 17:30:57 -0000 1.3 +++ Container.php 1 Aug 2002 19:55:11 -0000 @@ -176,6 +177,29 @@} // end func getUserdata /** + * Return the expiration date of a cached data set. + * + * @param string dataset ID + * @param string cache group + * @return integer expiration date + * @access public + */ + function getExpires($id, $group) { + if ($this->preload) { + if ($this->id != $id || $this->group != $group) + $this->preload($id, $group); + if ($this->unknown) + return FALSE; + return $this->expires; + } else { + if (!$this->isCached($id, $group)) + return FALSE; + list ($expires, , ) = $this->fetch($id, $group); + return $expires; + } + } // end func getExpires++ /** * Checks if a dataset is expired. * * @param string dataset ID@@ -185,28 +209,16 @@* @access public */ function isExpired($id, $group, $max_age) { - if ($this->preload) { - if ($this->id != $id || $this->group != $group) - $this->preload($id, $group); - - if ($this->unknown) - return false; - } else { - // check if at all it is cached - if (!$this->isCached($id, $group)) - return false; - - // I'm lazy... - list($this->expires, , ) = $this->fetch($id, $group); - } + $expires = $this->getExpires($id, $group); + if ($expires === FALSE) + return FALSE; // endless - if (0 == $this->expires) + if (0 == $expires) return false; // you feel fine, Ulf? - if ($expired = ($this->expires <= time() || ($max_age && ($this->expires <= $max_age))) ) {-+ if ($expired = ($expires <= time() || ($max_age && ($expires <= $max_age))) ) { $this->remove($id, $group); $this->flushPreload(); }------------------------------------------------------------------------ Index: Container.php =================================================================== RCS file: /repository/pear/Cache/Container.php,v retrieving revision 1.3 diff -u -r1.3 Container.php --- Container.php 12 Jul 2002 17:30:57 -0000 1.3 +++ Container.php 1 Aug 2002 20:06:19 -0000 @@ -98,9 +99,9 @@var $unknown = true; /** - * Encoding mode for cache data: base64 or addslashes() (slash). + * Encoding mode for cache data: base64 or convert to string (none). * - * @var string base64 or slash + * @var string base64 or none */ var $encoding_mode = 'base64'; @@ -389,7 +401,9 @@ * @var mixed data to encode */ function encode($data) { - if ('base64' == $this->encoding_mode) + if ('none' == $this->encoding_mode) + return $data; + elseif ('base64' == $this->encoding_mode) return base64_encode(serialize($data)); else return serialize($data);@@ -402,7 +416,9 @@* @var mixed */ function decode($data) { - if ('base64' == $this->encoding_mode) + if ('none' == $this->encoding_mode) + return $data; + elseif ('base64' == $this->encoding_mode) return unserialize(base64_decode($data)); else return unserialize($data);