lfsworldfilecache.php

Go to the documentation of this file.
00001 <?php
00013 require_once('Cache/Lite.php');
00014 require_once(dirname(__FILE__).'/../utilities/array_merge_replace.php');
00015 
00022 class LFSWorldFileCache
00023 {
00028     var $m_oCache = null;
00029     
00034      var $m_nLastUpdate = 0;
00035      
00040      var $m_aDefaults = array(  'group' => 'default',
00041                                 'noValidityCheck' => false);
00042       
00051     function LFSWorldFileCache(&$cache, $params=array())
00052     {
00053         $this->m_oCache =& $cache;
00054         $this->m_aDefaults = array_merge_recursive($this->m_aDefaults, $params);
00055     }
00056     
00064     function get($params)
00065     {
00066         $params = array_merge_replace($this->m_aDefaults, $params);
00067         if(!isset($params['key']))
00068             trigger_error('can\'t make a cache request without a key', E_USER_ERROR);
00069     
00070         //re-init cache with params
00071         $ctor = get_class($this->m_oCache); 
00072         $this->m_oCache->$ctor($params);
00073 
00074         $data = $this->m_oCache->get($params['key'], $params['group'], $params['noValidityCheck']);
00075         $lastUpdate = $this->_getLastUpdate();
00076         
00077         return array('lastUpdate' => $lastUpdate,
00078                      'data' => $data);
00079     }
00080     
00089     function save($data, $params)
00090     {
00091         $params = array_merge_replace($this->m_aDefaults, $params);
00092         if(count($params) != 0)
00093         {
00094             //re-init cache with params
00095             $ctor = get_class($this->m_oCache); 
00096             $this->m_oCache->$ctor($params);
00097         }
00098 
00099         $this->m_oCache->save($data, $params['key'], $params['group']);
00100         $this->m_nLastUpdate = time();
00101     }
00102 
00110     function createKey($uniqData)
00111     {
00112         return md5($uniqData);
00113     }
00114     
00121     function _getLastUpdate()
00122     {
00123         $this->m_nLastUpdate = (isset($this->m_oCache->_file) && file_exists($this->m_oCache->_file)) ? (filemtime($this->m_oCache->_file)) : (0);
00124         return $this->m_nLastUpdate;
00125     }
00126     
00133     function requiresDataReload()
00134     {
00135         return false;
00136     }
00137 }
00138 ?>

Generated on Wed Oct 25 03:13:32 2006 for LFSWorldParsingProviderFramework by  doxygen 1.4.6