Вход Регистрация
Файл: concrete5.7.5.6/concrete/vendor/zendframework/zend-cache/src/Storage/Adapter/ZendServerShm.php
Строк: 190
<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace ZendCacheStorageAdapter;

use 
ZendCacheException;
use 
ZendCacheStorageClearByNamespaceInterface;
use 
ZendCacheStorageFlushableInterface;
use 
ZendCacheStorageTotalSpaceCapableInterface;

class 
ZendServerShm extends AbstractZendServer implements
    
ClearByNamespaceInterface,
    
FlushableInterface,
    
TotalSpaceCapableInterface
{

    
/**
     * Constructor
     *
     * @param  null|array|Traversable|AdapterOptions $options
     * @throws ExceptionExtensionNotLoadedException
     */
    
public function __construct($options = array())
    {
        if (!
function_exists('zend_shm_cache_store')) {
            throw new 
ExceptionExtensionNotLoadedException("Missing 'zend_shm_cache_*' functions");
        } elseif (
PHP_SAPI == 'cli') {
            throw new 
ExceptionExtensionNotLoadedException("Zend server data cache isn't available on cli");
        }

        
parent::__construct($options);
    }

    
/* FlushableInterface */

    /**
     * Flush the whole storage
     *
     * @return bool
     */
    
public function flush()
    {
        return 
zend_shm_cache_clear();
    }

    
/* ClearByNamespaceInterface */

    /**
     * Remove items of given namespace
     *
     * @param string $namespace
     * @return bool
     */
    
public function clearByNamespace($namespace)
    {
        
$namespace = (string) $namespace;
        if (
$namespace === '') {
            throw new 
ExceptionInvalidArgumentException('No namespace given');
        }

        return 
zend_shm_cache_clear($namespace);
    }

    
/* TotalSpaceCapableInterface */

    /**
     * Get total space in bytes
     *
     * @return int|float
     */
    
public function getTotalSpace()
    {
        return (int) 
ini_get('zend_datacache.shm.memory_cache_size') * 1048576;
    }

    
/* internal */

    /**
     * Store data into Zend Data SHM Cache
     *
     * @param  string $internalKey
     * @param  mixed  $value
     * @param  int    $ttl
     * @return void
     * @throws ExceptionRuntimeException
     */
    
protected function zdcStore($internalKey$value$ttl)
    {
        if (!
zend_shm_cache_store($internalKey$value$ttl)) {
            
$valueType gettype($value);
            throw new 
ExceptionRuntimeException(
                
"zend_shm_cache_store($internalKey, <{$valueType}>, {$ttl}) failed"
            
);
        }
    }

    
/**
     * Fetch a single item from Zend Data SHM Cache
     *
     * @param  string $internalKey
     * @return mixed The stored value or NULL if item wasn't found
     * @throws ExceptionRuntimeException
     */
    
protected function zdcFetch($internalKey)
    {
        return 
zend_shm_cache_fetch((string) $internalKey);
    }

    
/**
     * Fetch multiple items from Zend Data SHM Cache
     *
     * @param  array $internalKeys
     * @return array All found items
     * @throws ExceptionRuntimeException
     */
    
protected function zdcFetchMulti(array $internalKeys)
    {
        
$items zend_shm_cache_fetch($internalKeys);
        if (
$items === false) {
            throw new 
ExceptionRuntimeException("zend_shm_cache_fetch(<array>) failed");
        }
        return 
$items;
    }

    
/**
     * Delete data from Zend Data SHM Cache
     *
     * @param  string $internalKey
     * @return bool
     * @throws ExceptionRuntimeException
     */
    
protected function zdcDelete($internalKey)
    {
        return 
zend_shm_cache_delete($internalKey);
    }
}
Онлайн: 1
Реклама