yf_cache_driver_apc class

Fileplugins/cache/classes/cache/yf_cache_driver_apc.class.php
Use_class('cache_driver_apc', 'classes/cache/')
Extendsyf_cache_driver

Public properties

A site sets them in its config with $PROJECT_CONF['cache_driver_apc']['NAME'] = ...;

PropertyDefaultDescription
$_connection null

Inherited properties

from yf_cache_driver: $_parent, $implemented

Public methods 7

del

public function del($name)
    public function del($name)
    {
        if ( ! $this->is_ready()) {
            return null;
        }
        return apcu_delete($name);
    }

flush

public function flush()
    public function flush()
    {
        if ( ! $this->is_ready()) {
            return null;
        }
        return apcu_clear_cache();
    }

get

public function get($name, $ttl = 0, $params = [])
    public function get($name, $ttl = 0, $params = [])
    {
        if ( ! $this->is_ready()) {
            return null;
        }
        $result = apcu_fetch($name);
        if (is_string($result)) {
            $try_unpack = unserialize($result);
            if ($try_unpack || substr($result, 0, 2) == 'a:') {
                $result = $try_unpack;
            }
            if ($result === 'false') {
                $result = false;
            }
        }
        return $result;
    }

is_ready

public function is_ready()
    public function is_ready()
    {
        return function_exists('apcu_fetch');
    }

set

public function set($name, $data, $ttl = 0)
    public function set($name, $data, $ttl = 0)
    {
        if ( ! $this->is_ready()) {
            return null;
        }
        if ($data === false) {
            $data = 'false';
        }
        return apcu_store($name, $data, $ttl);
    }

stats

public function stats()
    public function stats()
    {
        if ( ! $this->is_ready()) {
            return null;
        }
        $info = apcu_cache_info();
        $sma = apcu_sma_info();
        return [
            'hits' => isset($info['num_hits']) ? $info['num_hits'] : $info['nhits'],
            'misses' => isset($info['num_misses']) ? $info['num_misses'] : $info['nmisses'],
            'uptime' => isset($info['start_time']) ? $info['start_time'] : $info['stime'],
            'mem_usage' => $info['mem_size'],
            'mem_avail' => $sma['avail_mem'],
        ];
    }

Methods starting with _ hooks and helpers; not routable as page actions

__call

public function __call($name, $args)

Catch missing method call.

    public function __call($name, $args)
    {
        // Support for driver-specific methods
        if (is_object($this->_connection) && method_exists($this->_connection, $name)) {
            return call_user_func_array([$this->_connection, $name], $args);
        }
        return main()->extend_call($this, $name, $args);
    }