XOOPS  2.6.0
Cache.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
12 namespace Xmf\Module;
13 
15 
32 class Cache extends AbstractHelper
33 {
37  protected $prefix;
38 
42  protected $cache;
43 
49  public function init()
50  {
51  $this->prefix = array('module', $this->module->getVar('dirname'));
52  $this->cache = \Xoops::getInstance()->cache();
53  }
54 
62  private function prefix($name)
63  {
64  $prefixedName = $this->prefix;
65  if (!empty($name)) {
66  $name = (array) $name;
67  foreach ($name as $n) {
68  $prefixedName[] = $n;
69  }
70  }
71  return $prefixedName;
72  }
73 
85  public function write($key, $value, $ttl = null)
86  {
87  return $this->cache->write($this->prefix($key), $value);
88  }
89 
97  public function read($key)
98  {
99  return $this->cache->read($this->prefix($key));
100  }
101 
109  public function delete($key)
110  {
111  $this->cache->delete($this->prefix($key));
112  }
113 
130  public function cacheRead($cacheKey, $regenFunction, $ttl = null, $args = null)
131  {
132  return $this->cache->cacheRead($this->prefix($cacheKey), $regenFunction, $ttl, $args);
133  }
134 
141  public function clear()
142  {
143  return $this->delete(array());
144  }
145 }
static getInstance()
Definition: Xoops.php:160
write($key, $value, $ttl=null)
Definition: Cache.php:85
prefix($name)
Definition: Cache.php:62
cacheRead($cacheKey, $regenFunction, $ttl=null, $args=null)
Definition: Cache.php:130
read($key)
Definition: Cache.php:97