Changeset 444

Show
Ignore:
Timestamp:
01/06/08 03:07:38 (12 months ago)
Author:
padams
Message:

- refactored cacheFacade into a real facade instead of an abstract class so that it can be made plugable in the future.
- fixed php4 missing reference on cache class that was causing objects to not get persisted.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/base/classes/cache.php

    r437 r444  
    4141        var $collections; 
    4242        var $dirty_collections; 
    43         var $dirty_objs; 
     43        var $dirty_objs = array(); 
    4444        var $file_perms = 0775; 
    4545        var $dir_perms = 0775; 
     
    4747        var $non_persistant_collections = array(); 
    4848        var $mutex; 
    49  
     49        var $e; 
    5050 
    5151        /** 
     
    5656         * @param $cache_dir string 
    5757         */ 
    58         function __construct($cache_dir) { 
    59          
     58        function __construct($cache_dir = '') { 
     59                 
     60                $this->e = &owa_coreAPI::errorSingleton(); 
    6061                return $this->cache_dir = $cache_dir; 
    6162         
    6263        } 
    6364 
    64         function owa_cache($cache_dir) { 
     65        function owa_cache($cache_dir = '') { 
    6566                 
    6667                register_shutdown_function(array(&$this, "__destruct")); 
     
    9091                if (!in_array($collection, $this->non_persistant_collections)): 
    9192                        $this->dirty_objs[$collection][] = $hkey; 
     93                        //$this->debug(print_r($this->dirty_objs, true)); 
    9294                        $this->dirty_collections[$collection] = true;  
    9395                        $this->debug(sprintf('Added Object to Dirty List - Collection: %s, id: %s', $collection, $hkey)); 
     
    259261         
    260262        function __destruct() { 
    261          
     263                 
    262264                $this->persistCache(); 
    263265                $this->debug($this->getStats()); 
     
    269271        function persistCache() { 
    270272                 
     273                $this->debug("starting to persist cache..."); 
     274                 
    271275                // check for dirty objects 
    272276                if (!empty($this->dirty_objs)): 
    273                  
     277                         
     278                        $this->debug('Dirty Objects: '.print_r($this->dirty_objs, true)); 
     279                                 
    274280                        if ( ! $this->acquire_lock() ): 
     281                                $this->debug("could not persist cache due to not acquiring lock."); 
    275282                    return false; 
    276283                else: 
    277                  
     284                                $this->debug("starting to persist cache..."); 
    278285                                // make directories for collections 
    279286                                foreach ($this->dirty_collections as $k => $v) { 
     
    334341                        endif; 
    335342                        $this->release_lock(); 
     343                 
     344                else: 
     345                        $this->debug("There seem to be no dirty objects in the cache to persist."); 
    336346                endif; 
    337347         
     
    369379        function debug($msg) { 
    370380                 
    371                 print $msg.'<br>'; 
     381                $this->e->debug($msg); 
    372382                return; 
    373383        } 
  • trunk/modules/base/classes/cacheFacade.php

    r433 r444  
    3232require_once(OWA_BASE_CLASS_DIR.'cache.php'); 
    3333 
    34 class owa_cacheFacade extends owa_cache { 
     34class owa_cacheFacade extends owa_base { 
    3535 
    36         var $e; 
    37  
     36         
     37        var $cache; 
     38         
    3839        function __construct($cache_dir) { 
     40                 
     41                // make this plugable soon 
     42                $this->cache = &owa_coreAPI::supportClassFactory('base', 'cache'); 
     43                 
     44                if (!empty($cache_dir)): 
     45                        $this->setCacheDir($cache_dir); 
     46                endif; 
     47                 
     48                return; 
     49        } 
    3950         
    40                 $this->e = &owa_coreAPI::errorSingleton(); 
    41                 return parent::__construct($cache_dir); 
     51        function owa_cacheFacade($cache_dir) { 
     52                 
     53                return $this->__construct($cache_dir); 
     54         
     55        } 
     56         
     57        function get($collection, $key) { 
     58         
     59                return $this->cache->get($collection, $key); 
     60         
     61        } 
     62         
     63        function set($collection, $key, $value) { 
     64         
     65                return $this->cache->set($collection, $key, $value); 
    4266         
    4367        } 
    4468 
    45         function owa_cacheFacade($cache_dir) { 
     69        function remove($collection, $key) { 
    4670                 
    47                 $this->e = &owa_coreAPI::errorSingleton(); 
    48                 return $this->owa_cache($cache_dir); 
     71                return $this->cache->remove($collection, $key); 
     72        } 
    4973         
     74        function replace($collection, $key, $value) { 
     75                 
     76                return $this->cache->replace($collection, $key, $value); 
     77                 
     78        } 
     79         
     80        function setCacheDir($dir) { 
     81         
     82                return $this->cache->setCacheDir($dir); 
     83        } 
     84         
     85        function flush() { 
     86         
     87                return $this->cache->flush(); 
    5088        } 
    5189         
     
    5593                 
    5694        } 
     95         
     96        function setNonPersistantCollection($collection) { 
     97         
     98                return $this->cache->setNonPersistantCollection($collection); 
     99         
     100        } 
     101         
     102        function setGlobalCollection($collection) { 
     103                 
     104                return $this->cache->setGloballCollection($collection); 
     105 
     106        } 
     107         
    57108         
    58109        function error($msg) { 
  • trunk/owa_coreAPI.php

    r433 r444  
    311311        } 
    312312         
    313         function supportClassFactory($module, $class, $params = array()) { 
    314                  
    315                 $obj = owa_lib::factory(OWA_BASE_DIR.DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR, 'owa_', $class, $params); 
     313        function &supportClassFactory($module, $class, $params = array()) { 
     314                 
     315                $obj = &owa_lib::factory(OWA_BASE_DIR.DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR, 'owa_', $class, $params); 
    316316                $obj->module = $module; 
    317317