The APC cache adapter is meant to be used through the Cache interface, which abstracts away key generation, adapter instantiation and filter implementation. A simple configuration of this adapter can be accomplished in config/bootstrap/cache.php as follows: {{{ Cache::config(array( 'cache-config-name' => array('adapter' => 'Apc') )); }}} This APC adapter provides basic support for write, read, delete and clear cache functionality, as well as allowing the first four methods to be filtered as per the Lithium filtering system. Additionally, This adapter defines several methods that are _not_ implemented in other adapters, and are thus non-portable - see the documentation for Cache as to how these methods should be accessed. This adapter supports multi-key write, read and delete operations. Learn more about APC in the PHP APC manual.
See also: lithium\storage\Cache::key()
Inheritance: extends lithium\core\Object
示例#1
0
 public function testWriteDefaultCacheTime()
 {
     $Apc = new Apc(array('expiry' => '+5 seconds'));
     $key = 'key';
     $data = 'value';
     $closure = $Apc->write($key, $data);
     $this->assertTrue(is_callable($closure));
     $params = compact('key', 'data');
     $result = $closure($Apc, $params, null);
     $expected = $data;
     $this->assertTrue($result);
     $result = apc_fetch($key);
     $this->assertEqual($expected, $result);
     $result = apc_delete($key);
     $this->assertTrue($result);
 }
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2010, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */
/**
 * This file creates a default cache configuration using the most optimized adapter available, and
 * uses it to provide default caching for high-overhead operations.
 */
use lithium\storage\Cache;
use lithium\core\Libraries;
use lithium\action\Dispatcher;
use lithium\storage\cache\adapter\Apc;
/**
 * If APC is not available and the cache directory is not writeable, bail out.
 */
if (!($apcEnabled = Apc::enabled() && !is_writable(LITHIUM_APP_PATH . '/resources/tmp/cache'))) {
    return;
}
Cache::config(array('default' => array('adapter' => '\\lithium\\storage\\cache\\adapter\\' . ($apcEnabled ? 'Apc' : 'File'))));
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
    if ($cache = Cache::read('default', 'core.libraries')) {
        $cache = (array) unserialize($cache) + Libraries::cache();
        Libraries::cache($cache);
    }
    $result = $chain->next($self, $params, $chain);
    if ($cache != Libraries::cache()) {
        Cache::write('default', 'core.libraries', serialize(Libraries::cache()), '+1 day');
    }
    return $result;
});
示例#3
0
 * This file creates a default cache configuration using the most optimized adapter available, and
 * uses it to provide default caching for high-overhead operations.
 */
use lithium\storage\Cache;
use lithium\core\Libraries;
use lithium\action\Dispatcher;
use lithium\storage\cache\adapter\Apc;
if (PHP_SAPI === 'cli') {
    return;
}
/**
 * If APC is not available and the cache directory is not writeable, bail out. This block should be
 * removed post-install, and the cache should be configured with the adapter you plan to use.
 */
$cachePath = Libraries::get(true, 'resources') . '/tmp/cache';
if (!($apcEnabled = Apc::enabled()) && !is_writable($cachePath)) {
    return;
}
/**
 * This configures the default cache, based on whether ot not APC user caching is enabled. If it is
 * not, file caching will be used. Most of this code is for getting you up and running only, and
 * should be replaced with a hard-coded configuration, based on the cache(s) you plan to use.
 */
$default = array('adapter' => 'File', 'strategies' => array('Serializer'));
if ($apcEnabled) {
    $default = array('adapter' => 'Apc');
}
Cache::config(compact('default'));
/**
 * Caches paths for auto-loaded and service-located classes.
 */
示例#4
0
 public function testIncrementWithScope()
 {
     $adapter = new Apc(array('scope' => 'primary'));
     apc_store('primary:key1', 1, 60);
     apc_store('key1', 1, 60);
     $adapter->increment('key1');
     $expected = 1;
     $result = apc_fetch('key1');
     $this->assertEqual($expected, $result);
     $expected = 2;
     $result = apc_fetch('primary:key1');
     $this->assertEqual($expected, $result);
 }
示例#5
0
文件: cache.php 项目: nilamdoc/OxOPDF
 * `File`, `Redis`, `Apc`, `XCache` and `Memory`. Please see the documentation on the
 * adapters for specific characteristics and requirements.
 *
 * Most of this code is for getting you up and running only, and should be replaced with
 * a hard-coded configuration, based on the cache(s) you plan to use.
 *
 * We create a default cache configuration using the most optimized adapter available, and
 * use it to provide default caching for high-overhead operations. If APC is not available
 * and we can't degrade to file based caching, bail out.
 *
 * @see lithium\storage\Cache
 * @see lithium\storage\cache\adapters
 * @see lithium\storage\cache\strategies
 */
$cachePath = Libraries::get(true, 'resources') . '/tmp/cache';
if (!(($apc = Apc::enabled()) || PHP_SAPI === 'cli') && !is_writable($cachePath)) {
    return;
}
Cache::config(array('default' => array('adapter' => $apc ? 'Apc' : 'File', 'strategies' => $apc ? array() : array('Serializer'), 'scope' => $apc ? md5(LITHIUM_APP_PATH) : null)));
/**
 * Apply
 *
 * Applies caching to neuralgic points of the framework but only when we are running
 * in production. This is also a good central place to add your own caching rules.
 *
 * A couple of caching rules are already defined below:
 *  1. Cache paths for auto-loaded and service-located classes.
 *  2. Cache describe calls on all connections that use a `Database` based adapter.
 *
 * @see lithium\core\Environment
 * @see lithium\core\Libraries