123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace yii\caching;
- use yii\base\InvalidConfigException;
- class ApcCache extends Cache
- {
-
- public $useApcu = false;
-
- public function init()
- {
- parent::init();
- $extension = $this->useApcu ? 'apcu' : 'apc';
- if (!extension_loaded($extension)) {
- throw new InvalidConfigException("ApcCache requires PHP $extension extension to be loaded.");
- }
- }
-
- public function exists($key)
- {
- $key = $this->buildKey($key);
- return $this->useApcu ? apcu_exists($key) : apc_exists($key);
- }
-
- protected function getValue($key)
- {
- return $this->useApcu ? apcu_fetch($key) : apc_fetch($key);
- }
-
- protected function getValues($keys)
- {
- $values = $this->useApcu ? apcu_fetch($keys) : apc_fetch($keys);
- return is_array($values) ? $values : [];
- }
-
- protected function setValue($key, $value, $duration)
- {
- return $this->useApcu ? apcu_store($key, $value, $duration) : apc_store($key, $value, $duration);
- }
-
- protected function setValues($data, $duration)
- {
- $result = $this->useApcu ? apcu_store($data, null, $duration) : apc_store($data, null, $duration);
- return is_array($result) ? array_keys($result) : [];
- }
-
- protected function addValue($key, $value, $duration)
- {
- return $this->useApcu ? apcu_add($key, $value, $duration) : apc_add($key, $value, $duration);
- }
-
- protected function addValues($data, $duration)
- {
- $result = $this->useApcu ? apcu_add($data, null, $duration) : apc_add($data, null, $duration);
- return is_array($result) ? array_keys($result) : [];
- }
-
- protected function deleteValue($key)
- {
- return $this->useApcu ? apcu_delete($key) : apc_delete($key);
- }
-
- protected function flushValues()
- {
- return $this->useApcu ? apcu_clear_cache() : apc_clear_cache('user');
- }
- }
|