Re: Re: cvs: php4(PHP_4_0_6) /pear/Cache OutputCompression.php

From: Date: Tue, 15 May 2001 15:19:44 +0000
Subject: Re: Re: cvs: php4(PHP_4_0_6) /pear/Cache OutputCompression.php
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-386@lists.php.net to get a copy of this message
On Tue, May 15, 2001 at 09:09:28AM +0200, Christian Stocker wrote: > > In instances like this, I generally prefer to resort to the > > language rule of avoiding double-negatives. In the above case, > > we're looking at "if not no_cache" when it could more plainly be > > written as "if cache" (if the inverse being "if not cache", as > > opposed to "if no_cache"). In my opinion, this is much clearer > > when read in context. > > yes, it's clearer. but one reason against changing this is, that we then > have a api-change... not a big one, but nevertheless it's one.... I didn't realize that the existing $no_cache flag was intended to be externally visible (i.e. public). > and a lot of code has to be changed in Cache.php as well, otherwise it > will be broken. Yes, I make the mistake of not reviewing the code in Cache.php, as well. > As a temporary measure against the api change, we could write a > compatibility-line like > if ($this->no_cache == True) {$this->caching = False} > somewhere at the end in setoptions() in Container.php and write into the > docu that no_cache soon not will be supported anymore I'm not really all that concerned about breaking a part of the API right now, because I don't think many people are using the Cache classes. I can't say for sure, of course. The attached patch includes my previous changes, now extended to Cache.php, and adds two new accessors: getCaching() and setCaching(), which get and set the value of the $caching flag. I have also marked the $caching flag as private. In the future, there may be other code that might need to be executed when enabling or disabled caching, so it seems appropriate to add these two new functions in anticipation. It's also more "correct" from an OO encapsulation perspective. -- Jon Parise (jon@csh.rit.edu) . Rochester Inst. of Technology http://www.csh.rit.edu/~jon/ : Computer Science House Member

? caching.diff Index: Cache.php =================================================================== RCS file: /repository/php4/pear/Cache.php,v retrieving revision 1.11 diff -u -r1.11 Cache.php --- Cache.php 2001/04/24 08:27:11 1.11 +++ Cache.php 2001/05/15 15:10:57 @@ -65,14 +65,14 @@ class Cache extends PEAR { /** - * Disables the caching. + * Enables / disables caching. * * TODO: Add explanation what this is good for. * * @var boolean - * @access public + * @access private */ - var $no_cache = false; + var $caching = true; /** * Garbage collection: probability in seconds @@ -142,6 +142,28 @@ } /** + * Returns the current caching state. + * + * @return boolean The current caching state. + * @access public + */ + function getCaching() + { + return ($this->caching); + } + + /** + * Enables or disables caching. + * + * @param boolean The new caching state. + * @access public + */ + function setCaching($state) + { + $this->caching = $state; + } + + /** * Returns the requested dataset it if exists and is not expired * * @param string dataset ID @@ -150,7 +172,7 @@ * @access public */ function get($id, $group = "default") { - if ($this->no_cache) + if (!$this->caching) return ""; if ($this->isCached($id, $group) && !$this->isExpired($id, $group)) @@ -170,7 +192,7 @@ * @access public */ function save($id, $data, $expires = 0, $group = "default") { - if ($this->no_cache) + if (!$this->caching) return true; return $this->extSave($id, $data, "",$expires, $group); @@ -190,7 +212,7 @@ * @see getUserdata() */ function extSave($id, $cachedata, $userdata, $expires = 0, $group = "default") { - if ($this->no_cache) + if (!$this->caching) return true; return $this->container->save($id, $cachedata, $expires, $group, $userdata); @@ -205,7 +227,7 @@ * @access public */ function load($id, $group = "default") { - if ($this->no_cache) + if (!$this->caching) return ""; return $this->container->load($id, $group); @@ -221,7 +243,7 @@ * @see extSave() */ function getUserdata($id, $group = "default") { - if ($this->no_cache) + if (!$this->caching) return ""; return $this->container->getUserdata($id, $group); @@ -236,7 +258,7 @@ * @access public */ function delete($id, $group = "default") { - if ($this->no_cache) + if (!$this->caching) return true; return $this->container->delete($id, $group); @@ -249,7 +271,7 @@ * @return integer number of removed datasets */ function flush($group = "") { - if ($this->no_cache) + if (!$this->caching) return true; return $this->container->flush($group); @@ -266,7 +288,7 @@ * @access public */ function isCached($id, $group = "default") { - if ($this->no_cache) + if (!$this->caching) return false; return $this->container->isCached($id, $group); @@ -287,7 +309,7 @@ * @access public */ function isExpired($id, $group = "default", $max_age = 0) { - if ($this->no_cache) + if (!$this->caching) return true; return $this->container->isExpired($id, $group, $max_age); @@ -317,7 +339,7 @@ function garbageCollection($force = false) { static $last_run = 0; - if ($this->no_cache) + if (!$this->caching) return; srand((double) microtime() * 1000000); Index: Cache/Output.php =================================================================== RCS file: /repository/php4/pear/Cache/Output.php,v retrieving revision 1.15 diff -u -r1.15 Output.php --- Cache/Output.php 2001/03/17 16:06:31 1.15 +++ Cache/Output.php 2001/05/15 15:10:57 @@ -130,7 +130,7 @@ * @access public */ function start($id, $group = "default") { - if ($this->no_cache) + if (!$this->caching) return ""; // this is already cached return it from the cache so that the user @@ -163,7 +163,7 @@ ob_end_clean(); // store in the cache - if (!$this->no_cache) + if ($this->caching) $this->container->save($this->output_id, $content, $expire, $this->output_group, $userdata); return $content; Index: Cache/OutputCompression.php =================================================================== RCS file: /repository/php4/pear/Cache/OutputCompression.php,v retrieving revision 1.2 diff -u -r1.2 OutputCompression.php --- Cache/OutputCompression.php 2001/05/14 09:01:03 1.2 +++ Cache/OutputCompression.php 2001/05/15 15:10:57 @@ -84,7 +84,7 @@ function get($id, $group) { $this->content = ""; - if ($this->no_cache) + if (!$this->caching) return ""; if ($this->isCached($id, $group) && !$this->isExpired($id, $group)) @@ -105,7 +105,7 @@ ob_end_clean(); // store in the cache - if (!$this->no_cache) { + if ($this->caching) { $this->extSave($this->output_id, $content, $userdata, $expire, $this->output_group); return $this->content; } @@ -124,7 +124,7 @@ * */ function extSave($id, $cachedata, $userdata, $expires = 0, $group = "default") { - if ($this->no_cache) + if (!$this->caching) return true; if ($this->compression) { @@ -155,7 +155,7 @@ if ("" == $content) $content = &$this->content; - if ($this->compression && !$this->no_cache) { + if ($this->compression && $this->caching) { $etag = 'PEAR-Cache-' . md5(substr($content, -40)); header("ETag: $etag");
« previous php.pear.dev (#386) next »