|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00017 class Minify_Cache_APC { 00018 00029 public function __construct($expire = 0) 00030 { 00031 $this->_exp = $expire; 00032 } 00033 00043 public function store($id, $data) 00044 { 00045 return apc_store($id, "{$_SERVER['REQUEST_TIME']}|{$data}", $this->_exp); 00046 } 00047 00055 public function getSize($id) 00056 { 00057 return $this->_fetch($id) 00058 ? strlen($this->_data) 00059 : false; 00060 } 00061 00071 public function isValid($id, $srcMtime) 00072 { 00073 return ($this->_fetch($id) && ($this->_lm >= $srcMtime)); 00074 } 00075 00081 public function display($id) 00082 { 00083 echo $this->_fetch($id) 00084 ? $this->_data 00085 : ''; 00086 } 00087 00095 public function fetch($id) 00096 { 00097 return $this->_fetch($id) 00098 ? $this->_data 00099 : ''; 00100 } 00101 00102 private $_exp = null; 00103 00104 // cache of most recently fetched id 00105 private $_lm = null; 00106 private $_data = null; 00107 private $_id = null; 00108 00116 private function _fetch($id) 00117 { 00118 if ($this->_id === $id) { 00119 return true; 00120 } 00121 $ret = apc_fetch($id); 00122 if (false === $ret) { 00123 $this->_id = null; 00124 return false; 00125 } 00126 list($this->_lm, $this->_data) = explode('|', $ret, 2); 00127 $this->_id = $id; 00128 return true; 00129 } 00130 }