MemoryCache.php
Current file: /home/cristiano/expresso-api/prototype/api/cache/MemoryCache.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00% 0 / 1
40.00% 2 / 5 CRAP
50.00% 3 / 6
MemoryCache
0.00% 0 / 1
40.00% 2 / 5 8.12
50.00% 3 / 6
 __construct($conf=Null)
0.00% 0 / 1 2
0.00% 0 / 1
 put($id, $data, $expire=0, $compressed=false)
100.00% 1 / 1 1
100.00% 1 / 1
 get($id)
100.00% 1 / 1 1
100.00% 2 / 2
 clear($id)
0.00% 0 / 1 2
0.00% 0 / 1
 clearAll()
0.00% 0 / 1 2
0.00% 0 / 1


       1                 : <?php                                                                                             
       2                 : /**                                                                                               
       3                 :  * DooMemCache class file.                                                                        
       4                 :  *                                                                                                
       5                 :  * @author Leng Sheng Hong <darkredz@gmail.com>                                                   
       6                 :  * @link http://www.doophp.com/                                                                   
       7                 :  * @copyright Copyright &copy; 2009 Leng Sheng Hong                                               
       8                 :  * @license http://www.doophp.com/license                                                         
       9                 :  */                                                                                               
      10                 :                                                                                                   
      11                 :                                                                                                   
      12                 : /**                                                                                               
      13                 :  * DooMemCache provides caching methods utilizing the Memcache extension.                         
      14                 :  *                                                                                                
      15                 :  * If you have multiple servers for memcache, you would have to set it up in common.conf.php      
      16                 :  * <code>                                                                                         
      17                 :  * // host, port, persistent, weight                                                              
      18                 :  * $config['MEMCACHE'] = array(                                                                   
      19                 :  *                       array('192.168.1.31', '11211', true, 40),                                
      20                 :  *                       array('192.168.1.23', '11211', true, 80)                                 
      21                 :  *                     );                                                                         
      22                 :  * </code>                                                                                        
      23                 :  *                                                                                                
      24                 :  * @author Leng Sheng Hong <darkredz@gmail.com>                                                   
      25                 :  * @version $Id: DooMemCache.php 1000 2009-08-22 19:36:10                                         
      26                 :  * @package doo.cache                                                                             
      27                 :  * @since 1.1                                                                                     
      28                 :  */                                                                                               
      29                 :                                                                                                   
      30                 : class MemoryCache{                                                                                
      31                 :     /**                                                                                           
      32                 :      * Memcached connection                                                                       
      33                 :      * @var Memcache                                                                              
      34                 :      */                                                                                           
      35                 :     protected $_memcache;                                                                         
      36                 :                                                                                                   
      37                 :     /**                                                                                           
      38                 :      * Configurations of the connections                                                          
      39                 :      * @var array                                                                                 
      40                 :      */                                                                                           
      41                 :     protected $_config;                                                                           
      42                 :                                                                                                   
      43                 :     public function  __construct($conf=Null) {                                                    
      44                 :         //$this->_memcache = new Memcache();                                                      
      45                 : //        $this->_config = $conf;                                                                 
      46                 :                                                                                                   
      47                 :         // host, port, persistent, weight                                                         
      48                 : //        if($conf!==Null){                                                                       
      49                 : //            foreach ($conf as $c){                                                              
      50                 : //                $result = $this->_memcache->addServer($c[0], $c[1], $c[2], $c[3]);              
      51                 : //            }                                                                                   
      52                 : //        }                                                                                       
      53                 : //        else{                                                                                   
      54                 : //            $this->_memcache->addServer('localhost', 11211);                                    
      55                 : //        }                                                                                       
      56               0 :     }                                                                                             
      57                 :                                                                                                   
      58                 :     /**                                                                                           
      59                 :      * Adds a cache with an unique Id.                                                            
      60                 :      *                                                                                            
      61                 :      * @param string $id Cache Id                                                                 
      62                 :      * @param mixed $data Data to be stored                                                       
      63                 :      * @param int $expire Seconds to expired                                                      
      64                 :      * @param int $compressed To store the data in Zlib compressed format                         
      65                 :      * @return bool True if success                                                               
      66                 :      */                                                                                           
      67                 :     public function put($id, $data, $expire=0, $compressed=false){                                
      68                 :                                                                                                   
      69                 :                                                                                                   
      70                 : //         if($compressed)                                                                        
      71                 : //             return $this->_memcache->set($id, $data, MEMCACHE_COMPRESSED, $expire);            
      72                 : //         else                                                                                   
      73                 : //             return $this->_memcache->set($id, $data, 0, $expire);                              
      74               1 :     return false;                                                                                 
      75                 :     }                                                                                             
      76                 :                                                                                                   
      77                 :     /**                                                                                           
      78                 :      * Retrieves a value from cache with an Id.                                                   
      79                 :      *                                                                                            
      80                 :      * @param string $id A unique key identifying the cache                                       
      81                 :      * @return mixed The value stored in cache. Return false if no cache found or already expired.
      82                 :      */                                                                                           
      83                 :     public function get($id){                                                                     
      84                 :                                                                                                   
      85                 : //         $return = $this->_memcache->get($id);                                                  
      86               1 :       $return = false;                                                                            
      87                 :                                                                                                   
      88               1 :     return( $return );                                                                            
      89                 :     }                                                                                             
      90                 :                                                                                                   
      91                 :     /**                                                                                           
      92                 :      * Deletes an APC data cache with an identifying Id                                           
      93                 :      *                                                                                            
      94                 :      * @param string $id Id of the cache                                                          
      95                 :      * @return bool True if success                                                               
      96                 :      */                                                                                           
      97                 :     public function clear($id){                                                                   
      98               0 :         return $this->_memcache->delete($id);                                                     
      99                 :     }                                                                                             
     100                 :                                                                                                   
     101                 :     /**                                                                                           
     102                 :      * Deletes all data cache                                                                     
     103                 :      * @return bool True if success                                                               
     104                 :      */                                                                                           
     105                 :     public function clearAll(){                                                                   
     106               0 :         return $this->_memcache->flush();                                                         
     107                 :     }                                                                                             
     108                 :                                                                                                   
     109                 : }                                                                                                 
     110                 :                                                                                                   

Generated by PHP_CodeCoverage 1.1.2 using PHP 5.3.10 and PHPUnit 3.6.10 at Thu Mar 29 15:14:42 BRT 2012.