Cache::exists PHP Method

exists() public method

Return timestamp and TTL of cache entry or FALSE if not found
public exists ( $key, &$val = NULL ) : array | FALSE
$key string
$val mixed
return array | FALSE
    function exists($key, &$val = NULL)
    {
        $fw = Base::instance();
        if (!$this->dsn) {
            return FALSE;
        }
        $ndx = $this->prefix . '.' . $key;
        $parts = explode('=', $this->dsn, 2);
        switch ($parts[0]) {
            case 'apc':
            case 'apcu':
                $raw = apc_fetch($ndx);
                break;
            case 'redis':
                $raw = $this->ref->get($ndx);
                break;
            case 'memcache':
                $raw = memcache_get($this->ref, $ndx);
                break;
            case 'wincache':
                $raw = wincache_ucache_get($ndx);
                break;
            case 'xcache':
                $raw = xcache_get($ndx);
                break;
            case 'folder':
                $raw = $fw->read($parts[1] . $ndx);
                break;
        }
        if (!empty($raw)) {
            list($val, $time, $ttl) = (array) $fw->unserialize($raw);
            if ($ttl === 0 || $time + $ttl > microtime(TRUE)) {
                return [$time, $ttl];
            }
            $val = null;
            $this->clear($key);
        }
        return FALSE;
    }

Usage Example

コード例 #1
0
 public function testExistsNoToString()
 {
     $object = new CacheTestNoToSTring();
     $cache = new Cache();
     $this->setExpectedException('PHPUnit_Framework_Error');
     $cache->exists($object);
 }
All Usage Examples Of Cache::exists