sbergmann               Thu Mar  1 09:18:23 2001 EDT

  Modified files:              
    /php4/pear/Cache    Container.php 
    /php4/pear/Cache/Container  file.php phplib.php shm.php 
  Log:
  Added flushPreload() method.
  
Index: php4/pear/Cache/Container.php
diff -u php4/pear/Cache/Container.php:1.1 php4/pear/Cache/Container.php:1.2
--- php4/pear/Cache/Container.php:1.1   Thu Mar  1 08:32:29 2001
+++ php4/pear/Cache/Container.php       Thu Mar  1 09:18:22 2001
@@ -16,7 +16,7 @@
 // |          Sebastian Bergmann <[EMAIL PROTECTED]>               |
 // +----------------------------------------------------------------------+
 //
-// $Id: Container.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $
+// $Id: Container.php,v 1.2 2001/03/01 17:18:22 sbergmann Exp $
 
 /**
 * Common base class of all cache storage container.
@@ -36,7 +36,7 @@
 * not recommended!
 * 
 * @author   Ulf Wendel <[EMAIL PROTECTED]>
-* @version  $Id: Container.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $
+* @version  $Id: Container.php,v 1.2 2001/03/01 17:18:22 sbergmann Exp $
 * @package  Cache
 * @access   public
 * @abstract
@@ -147,13 +147,8 @@
         if ($expired  = ($this->expires <= time() || ($max_age && $this->expires <= 
time() + $max_age)) ) {        
            
            $this->delete($id);
+           $this->flushPreload();
            
-           // remove preloaded values
-           $this->id = "";
-           $this->data = "";
-           $this->expires = 0;
-           $this->unknown = true;
-           
         }
         
         return $expired;
@@ -210,6 +205,7 @@
     * @abstract
     */
     function save($id, $data, $expire = 0) {
+        $this->flushPreload($id);
         return NULL;
     } // end func save
     
@@ -223,6 +219,7 @@
     * @abstract
     */     
     function delete($id) {
+        $this->flushPreload($id);
         return NULL;
     } // end func delete
     
@@ -235,6 +232,7 @@
     * @abstract
     */
     function flush() {
+        $this->flushPreload();
         return NULL;
     } // end func flush
     
@@ -257,6 +255,7 @@
     * @abstract
     */
     function garbageCollection() {
+        $this->flushPreload();
     } // end func garbageCollection
 
     /**
@@ -288,6 +287,27 @@
         return true;
     } // end func preload
     
+    /**
+    * Flushes the internal preload buffer.
+    *
+    * save(), delete() and flush() must call this method
+    * to preevent differences between the preloaded values and 
+    * the real cache contents.
+    *
+    * @see  preload()
+    */
+    function flushPreload($id = "") {
+
+        if (!$id || $this->id == $id) {
+            // clear the internal preload values
+            $this->id = "";
+            $this->data = "";
+            $this->expires = -1;
+            $this->unknown = true;
+        }
+        
+    } // end func flushPreload
+
     /**
     * Imports the requested datafields as object variables if allowed
     * 
Index: php4/pear/Cache/Container/file.php
diff -u php4/pear/Cache/Container/file.php:1.1 php4/pear/Cache/Container/file.php:1.2
--- php4/pear/Cache/Container/file.php:1.1      Thu Mar  1 08:32:29 2001
+++ php4/pear/Cache/Container/file.php  Thu Mar  1 09:18:23 2001
@@ -16,7 +16,7 @@
 // |          Sebastian Bergmann <[EMAIL PROTECTED]>               |
 // +----------------------------------------------------------------------+
 //
-// $Id: file.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $
+// $Id: file.php,v 1.2 2001/03/01 17:18:23 sbergmann Exp $
 
 require_once 'Cache/Container.php';
 
@@ -24,7 +24,7 @@
 * Stores cache contents in a file.
 *
 * @author   Ulf Wendel  <[EMAIL PROTECTED]>
-* @version  $Id: file.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $
+* @version  $Id: file.php,v 1.2 2001/03/01 17:18:23 sbergmann Exp $
 */
 class Cache_Container_file extends Cache_Container {
 
@@ -94,6 +94,8 @@
     
     function save($id, $data, $expire = 0) {
         
+        $this->flushPreload($id);
+
         $file = $this->getFilename($id);
         if (!($fh = @fopen($file, "wb")))
             return new CacheError("Can't access '$file' to store cache data. Check 
access rights and path.", __FILE__, __LINE__);
@@ -115,6 +117,8 @@
     
     function delete($id) {
         
+        $this->flushPreload($id);
+
         $file = $this->getFilename($id);
         if (file_exists($file)) {
             
@@ -130,6 +134,8 @@
     
     function flush() {
         
+        $this->flushPreload();
+
         if (!($dh = opendir($this->cache_dir)))
             return new CacheError("Can't access the cache directory 
'$this->cache_dir'. Check access rights and path", __FILE__, __LINE__);
 
@@ -167,6 +173,8 @@
     */
     function garbageCollection() {
         
+        $this->flushPreload();      
+
         if (!($dh = opendir($this->cache_dir)))
             return new CacheError("Can't access cache directory.", __FILE__, 
__LINE__);
 
Index: php4/pear/Cache/Container/phplib.php
diff -u php4/pear/Cache/Container/phplib.php:1.1 
php4/pear/Cache/Container/phplib.php:1.2
--- php4/pear/Cache/Container/phplib.php:1.1    Thu Mar  1 08:32:29 2001
+++ php4/pear/Cache/Container/phplib.php        Thu Mar  1 09:18:23 2001
@@ -16,7 +16,7 @@
 // |          Sebastian Bergmann <[EMAIL PROTECTED]>               |
 // +----------------------------------------------------------------------+
 //
-// $Id: phplib.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $
+// $Id: phplib.php,v 1.2 2001/03/01 17:18:23 sbergmann Exp $
 
 require_once 'Cache/Container.php';
 
@@ -37,7 +37,7 @@
 * Stores cache data into a database table.
 * 
 * @author   Ulf Wendel  <[EMAIL PROTECTED]>, Sebastian Bergmann 
<[EMAIL PROTECTED]>
-* @version  $Id: phplib.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $
+* @version  $Id: phplib.php,v 1.2 2001/03/01 17:18:23 sbergmann Exp $
 * @package  Cache
 */
 class Cache_Container_phplib extends Cache_Container {
@@ -128,6 +128,8 @@
     
     function save($id, $data, $expires = 0) {
         
+        $this->flushPreload($id);
+
         $query = sprintf("REPLACE INTO %s (data, expires, id) VALUES ('%s', %d, 
'%s')",
                             $this->cache_table,
                             $this->encode($data),
@@ -142,6 +144,8 @@
     
     function delete($id) {
         
+        $this->flushPreload($id);
+
         $query = sprintf("DELETE FROM %s WHERE id = '%s'",
                             $this->cache_table,
                             $id
@@ -154,6 +158,8 @@
     
     function flush() {
         
+        $this->flushPreload();
+
         $query = sprintf("DELETE FROM %s", $this->cache_table);
         $this->db->query($query);
 
@@ -173,6 +179,8 @@
     
     function garbageCollection() {
         
+        $this->flushPreload();
+
         $query = sprintf("DELETE FORM %s WHERE expires <= %d AND expires > 0", 
                             $this->cache_table, 
                             time()
Index: php4/pear/Cache/Container/shm.php
diff -u php4/pear/Cache/Container/shm.php:1.1 php4/pear/Cache/Container/shm.php:1.2
--- php4/pear/Cache/Container/shm.php:1.1       Thu Mar  1 08:32:29 2001
+++ php4/pear/Cache/Container/shm.php   Thu Mar  1 09:18:23 2001
@@ -17,7 +17,7 @@
 // |          Björn Schotte <[EMAIL PROTECTED]>                              |
 // +----------------------------------------------------------------------+
 //
-// $Id: shm.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $
+// $Id: shm.php,v 1.2 2001/03/01 17:18:23 sbergmann Exp $
 
 require_once 'Cache/Container.php';
 
@@ -25,7 +25,7 @@
 * Stores cache data into shared memory.
 *
 * @author   Björn Schotte <[EMAIL PROTECTED]>
-* @version  $Id: shm.php,v 1.1 2001/03/01 16:32:29 chagenbu Exp $
+* @version  $Id: shm.php,v 1.2 2001/03/01 17:18:23 sbergmann Exp $
 * @package  Cache
 */
 class Cache_Container_shm extends Cache_Container {
@@ -40,14 +40,17 @@
     
     function save($id, $data, $expires = 0)
     {
+        $this->flushPreload($id);
     } // end func save
     
     function delete($id)
     {
+        $this->flushPreload($id);
     } // end func delete
     
     function flush()
     {
+        $this->flushPreload();
     } // end func flush
     
     function idExists($id)



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to