XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
CacheHandler.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
9 class CacheHandler extends Handler
10 {
15  var $handler = null;
16 
21  var $keyGroupVersions = null;
22 
31  function &getInstance($target = 'object', $info = null, $always_use_file = false)
32  {
33  $cache_handler_key = $target . ($always_use_file ? '_file' : '');
34  if(!$GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key])
35  {
36  $GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key] = new CacheHandler($target, $info, $always_use_file);
37  }
38  return $GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key];
39  }
40 
52  function __construct($target, $info = null, $always_use_file = false)
53  {
54  if(!$info)
55  {
56  $info = Context::getDBInfo();
57  }
58 
59  if($info)
60  {
61  if($target == 'object')
62  {
63  if($info->use_object_cache == 'apc')
64  {
65  $type = 'apc';
66  }
67  else if(substr($info->use_object_cache, 0, 8) == 'memcache')
68  {
69  $type = 'memcache';
70  $url = $info->use_object_cache;
71  }
72  else if($info->use_object_cache == 'wincache')
73  {
74  $type = 'wincache';
75  }
76  else if($info->use_object_cache == 'file')
77  {
78  $type = 'file';
79  }
80  else if($always_use_file)
81  {
82  $type = 'file';
83  }
84  }
85  else if($target == 'template')
86  {
87  if($info->use_template_cache == 'apc')
88  {
89  $type = 'apc';
90  }
91  else if(substr($info->use_template_cache, 0, 8) == 'memcache')
92  {
93  $type = 'memcache';
94  $url = $info->use_template_cache;
95  }
96  else if($info->use_template_cache == 'wincache')
97  {
98  $type = 'wincache';
99  }
100  }
101 
102  if($type)
103  {
104  $class = 'Cache' . ucfirst($type);
105  include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class);
106  $this->handler = call_user_func(array($class, 'getInstance'), $url);
107  $this->keyGroupVersions = $this->handler->get('key_group_versions', 0);
108  if(!$this->keyGroupVersions)
109  {
110  $this->keyGroupVersions = array();
111  $this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
112  }
113  }
114  }
115  }
116 
122  function isSupport()
123  {
124  if($this->handler && $this->handler->isSupport())
125  {
126  return true;
127  }
128 
129  return false;
130  }
131 
138  function getCacheKey($key)
139  {
140  $key = str_replace('/', ':', $key);
141 
142  return __XE_VERSION__ . ':' . $key;
143  }
144 
153  function get($key, $modified_time = 0)
154  {
155  if(!$this->handler)
156  {
157  return false;
158  }
159 
160  $key = $this->getCacheKey($key);
161 
162  return $this->handler->get($key, $modified_time);
163  }
164 
175  function put($key, $obj, $valid_time = 0)
176  {
177  if(!$this->handler && !$key)
178  {
179  return false;
180  }
181 
182  $key = $this->getCacheKey($key);
183 
184  return $this->handler->put($key, $obj, $valid_time);
185  }
186 
193  function delete($key)
194  {
195  if(!$this->handler)
196  {
197  return false;
198  }
199 
200  $key = $this->getCacheKey($key);
201 
202  return $this->handler->delete($key);
203  }
204 
213  function isValid($key, $modified_time = 0)
214  {
215  if(!$this->handler)
216  {
217  return false;
218  }
219 
220  $key = $this->getCacheKey($key);
221 
222  return $this->handler->isValid($key, $modified_time);
223  }
224 
230  function truncate()
231  {
232  if(!$this->handler)
233  {
234  return false;
235  }
236 
237  return $this->handler->truncate();
238  }
239 
256  function getGroupKey($keyGroupName, $key)
257  {
258  if(!$this->keyGroupVersions[$keyGroupName])
259  {
260  $this->keyGroupVersions[$keyGroupName] = 1;
261  $this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
262  }
263 
264  return 'cache_group_' . $this->keyGroupVersions[$keyGroupName] . ':' . $keyGroupName . ':' . $key;
265  }
266 
273  function invalidateGroupKey($keyGroupName)
274  {
275  $this->keyGroupVersions[$keyGroupName]++;
276  $this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
277  }
278 
279 }
280 
287 {
292  var $valid_time = 36000;
293 
302  function get($key, $modified_time = 0)
303  {
304  return false;
305  }
306 
317  function put($key, $obj, $valid_time = 0)
318  {
319  return false;
320  }
321 
330  function isValid($key, $modified_time = 0)
331  {
332  return false;
333  }
334 
340  function isSupport()
341  {
342  return false;
343  }
344 
350  function truncate()
351  {
352  return false;
353  }
354 
355 }
356 /* End of file CacheHandler.class.php */
357 /* Location: ./classes/cache/CacheHandler.class.php */
const __XE_VERSION__
Definition: config.inc.php:32
$obj
Definition: ko.install.php:262
if(file_exists(_XE_PATH_. 'config/config.user.inc.php')) if(!defined('__DEBUG__')) if(!defined('__DEBUG_OUTPUT__')) if(!defined('__DEBUG_PROTECT__')) if(!defined('__DEBUG_PROTECT_IP__')) if(!defined('__DEBUG_DB_OUTPUT__')) if(!defined('__LOG_SLOW_QUERY__')) if(!defined('__LOG_SLOW_TRIGGER__')) if(!defined('__LOG_SLOW_ADDON__')) if(!defined('__LOG_SLOW_WIDGET__')) if(!defined('__DEBUG_QUERY__')) if(!defined('__OB_GZHANDLER_ENABLE__')) if(!defined('__ENABLE_PHPUNIT_TEST__')) if(!defined('__PROXY_SERVER__')) if(!defined('__ERROR_LOG__')) if(!defined('__DISABLE_DEFAULT_CSS__')) if(!defined('__AUTO_OPCACHE_INVALIDATE__')) if((__DEBUG_OUTPUT__==2)&&version_compare(PHP_VERSION, '6.0.0')===-1) if(version_compare(PHP_VERSION, '5.3.0') >=0) $GLOBALS['__xe_autoload_file_map']
Definition: config.inc.php:324
& getInstance($target= 'object', $info=null, $always_use_file=false)
__construct($target, $info=null, $always_use_file=false)
invalidateGroupKey($keyGroupName)
put($key, $obj, $valid_time=0)
isValid($key, $modified_time=0)
put($key, $obj, $valid_time=0)
const _XE_PATH_
Definition: config.inc.php:49
isValid($key, $modified_time=0)
getGroupKey($keyGroupName, $key)