XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
model.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
54 {
63  var $settings = array();
64 
71  var $model = null;
72 
79  var $fields = array();
80 
91  function init($settings)
92  {
94 
95  parent::init($settings);
96  $defaults = array('fields' => array('data' , 'expires'));
97  $this->settings = array_merge($defaults, $this->settings);
98  $this->fields = $this->settings['fields'];
99  $this->model = new XoopsCacheModelHandler($xoopsDB);
100  return true;
101  }
102 
108  function gc()
109  {
110  return $this->model->deleteAll(new Criteria($this->fields[1], time, '<= '));
111  }
112 
122  function write($key, $data, $duration)
123  {
124  // if (isset($this->settings['serialize'])) {
125  $data = serialize($data);
126  // }
127  if (! $data) {
128  return false;
129  }
130  $cache_obj = $this->model->create();
131  $cache_obj->setVar($this->model::KEYNAME, $key);
132  $cache_obj->setVar($this->fields[0], $data);
133  $cache_obj->setVar($this->fields[1], time() + $duration);
134  return $this->model->insert($cache_obj);
135  }
136 
144  function read($key)
145  {
146  $criteria = new CriteriaCompo(new Criteria($this->model::KEYNAME, $key));
147  $criteria->add(new Criteria($this->fields[1], time(), ">"));
148  $criteria->setLimit(1);
149  $data = $this->model->getAll($criteria);
150  if (!$data) {
151  return null;
152  }
153  return unserialize($data[0]);
154  }
155 
163  function delete($key)
164  {
165  return $this->model->delete($key);
166  }
167 
174  function clear()
175  {
176  return $this->model->deleteAll();
177  }
178 }
179 
190 {
192  {
193  $this->__construct();
194  }
195 
196  function __construct()
197  {
198  parent::__construct();
199  $this->initVar('key', XOBJ_DTYPE_TXTBOX);
200  $this->initVar('data', XOBJ_DTYPE_SOURCE);
201  $this->initVar('expires', XOBJ_DTYPE_INT);
202  }
203 }
204 
215 {
216  const TABLE = 'cache_model';
217  const CLASSNAME = 'XoopsCacheModelObject';
218  const KEYNAME = 'key';
219 }
220 
221 ?>