Hoa central
Eaccelerator.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Cache\Backend;
38 
39 use Hoa\Cache;
40 
50 class Eaccelerator extends Backend
51 {
59  public function __construct(Array $parameters = [])
60  {
61  if (!extension_loaded('eaccelerator')) {
62  throw new Cache\Exception(
63  'EAccelerator is not loaded on server.',
64  0
65  );
66  }
67 
68  parent::__construct($parameters);
69 
70  return;
71  }
72 
80  public function store($data)
81  {
82  $this->clean();
83 
84  return eaccelerator_put(
85  $this->getIdMd5(),
86  serialize($data),
87  $this->_parameters->getParameter('lifetime')
88  );
89  }
90 
97  public function load()
98  {
99  $this->clean();
100 
101  $content = eaccelerator_get($this->getIdMd5());
102 
103  return unserialize($content);
104  }
105 
115  public function clean($lifetime = Cache::CLEAN_EXPIRED)
116  {
117  switch ($lifetime) {
118  case Cache::CLEAN_ALL:
119  $infos = eaccelerator_list_keys();
120 
121  // EAccelerator bug (http://eaccelerator.net/ticket/287).
122  foreach ($infos as $foo => $info) {
123  $key =
124  0 === strpos($info['name'], ':')
125  ? substr($info['name'], 1)
126  : $info['name'];
127 
128  if (false === eaccelerator_rm($key)) {
129  throw new \Hoa\Cache\Exception(
130  'Remove all existing cache file failed ' .
131  '(maybe for the %s cache).',
132  1,
133  $key
134  );
135  }
136  }
137 
138  break;
139 
141  // Manage by EAccelerator.
142  break;
143 
144  case Cache::CLEAN_USER:
145  throw new \Hoa\Cache\Exception(
146  '\Hoa\Cache::CLEAN_USER constant is not supported by ' .
147  'EAccelerator backend.',
148  2
149  );
150  }
151 
152  return;
153  }
154 
160  public function remove()
161  {
162  eaccelerator_rm($this->getIdMd5());
163 
164  return;
165  }
166 }
clean($lifetime=Cache::CLEAN_EXPIRED)
const CLEAN_EXPIRED
Definition: Cache.php:62
__construct(Array $parameters=[])
const CLEAN_ALL
Definition: Cache.php:55
$content
Definition: Hoa.php:119
const CLEAN_USER
Definition: Cache.php:69