MkFramework
 All Data Structures Functions
class_cacheVar.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
23 class _cacheVar{
24 
25  protected $_oFile=null;
26 
27  private function load($sId){
28  if($this->_oFile){
29  return;
30  }
31  $oFile=new _file(_root::getConfigVar('path.cache').$sId.'.cachevar');
32  $this->_oFile=$oFile;
33  }
34 
42  public function isCached($sId,$iMinute=null){
43  $this->load($sId);
44  if($this->_oFile->exist()){
45  if($iMinute==null){
46  return true;
47  }else if( (time()-$this->_oFile->filemtime()) < ($iMinute*60)){
48  return true;
49  }
50  return false;
51  }
52  return false;
53  }
59  public function getCached($sId){
60  $this->load($sId);
61  $uData=unserialize($this->_oFile->getContent());
62  return $uData;
63  }
69  public function setCache($sId,$uData){
70  $this->load($sId);
71  $sData=serialize($uData);
72 
73  $this->_oFile->setContent($sData );
74  $this->_oFile->save();
75  }
81  public function clearCache($sId){
82  $this->load($sId);
83  $this->_oFile->delete();
84  }
85 
86 
87 }
isCached($sId, $iMinute=null)
static getConfigVar($sCatAndVar, $uDefaut=null)
Definition: class_root.php:654
setCache($sId, $uData)
clearCache($sId)
getCached($sId)