Hoa central
Apc.php
Go to the documentation of this file.
1 <?php
2 
38 
39 use Hoa\Cache;
40 
51 class Apc extends Backend
52 {
60  public function __construct(Array $parameters = [])
61  {
62  if (!extension_loaded('apc')) {
63  throw new Cache\Exception(
64  'APC (PECL extension) is not loaded on server.',
65  0
66  );
67  }
68 
69  parent::__construct($parameters);
70 
71  return;
72  }
73 
80  public function store($data)
81  {
82  $this->clean();
83 
84  if (false !== $this->_parameters->getParameter('serialize_content')) {
85  $data = serialize($data);
86  }
87 
88  return apc_store(
89  $this->getIdMd5(),
90  $data,
91  $this->_parameters->getParameter('lifetime')
92  );
93  }
94 
100  public function load()
101  {
102  $this->clean();
103 
104  $content = apc_fetch($this->getIdMd5());
105 
106  if (true === $this->_parameters->getParameter('serialize_content')) {
107  $content = unserialize($content);
108  }
109 
110  return $content;
111  }
112 
121  public function clean($lifetime = Cache::CLEAN_USER)
122  {
123  switch ($lifetime) {
124  case Cache::CLEAN_ALL:
125  return apc_clear_cache();
126 
128  throw new Cache\Exception(
129  '\Hoa\Cache::CLEAN_EXPIRED constant is not supported by ' .
130  'APC cache backend.',
131  1
132  );
133 
134  case Cache::CLEAN_USER:
135  default:
136  return apc_clear_cache('user');
137  }
138 
139  return;
140  }
141 
147  public function remove()
148  {
149  apc_delete($this->getIdMd5());
150 
151  return;
152  }
153 }
const CLEAN_EXPIRED
Definition: Cache.php:62
clean($lifetime=Cache::CLEAN_USER)
Definition: Apc.php:121
__construct(Array $parameters=[])
Definition: Apc.php:60
const CLEAN_ALL
Definition: Cache.php:55
$content
Definition: Hoa.php:119
const CLEAN_USER
Definition: Cache.php:69