本文整理汇总了PHP中Cache::engine方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::engine方法的具体用法?PHP Cache::engine怎么用?PHP Cache::engine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::engine方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInitSettings
function testInitSettings()
{
Cache::engine('File', array('path' => TMP . 'tests'));
$settings = Cache::settings();
$expecting = array('duration' => 3600, 'probability' => 100, 'path' => TMP . 'tests', 'prefix' => 'cake_', 'lock' => false, 'serialize' => true);
$this->assertEqual($settings, $expecting);
}
示例2: skip
function skip()
{
$skip = true;
if ($result = Cache::engine('Apc')) {
$skip = false;
}
$this->skipif($skip, 'APCEngineTest not implemented');
}
示例3: skip
/**
* skip method
*
* @access public
* @return void
*/
function skip()
{
$skip = true;
if (Cache::engine('Apc')) {
$skip = false;
}
$this->skipif($skip, 'Apc is not installed or configured properly');
}
示例4: skip
/**
* skip method
*
* @access public
* @return void
*/
function skip()
{
$skip = true;
if ($result = Cache::engine('Xcache')) {
$skip = false;
}
$this->skipIf($skip, '%s Xcache is not installed or configured properly');
}
示例5: testWriteQuotedString
/**
* testWriteQuotedString method
*
* @access public
* @return void
*/
function testWriteQuotedString()
{
Cache::engine('File', array('path' => TMP . 'tests'));
Cache::write('App.doubleQuoteTest', '"this is a quoted string"');
$this->assertIdentical(Cache::read('App.doubleQuoteTest'), '"this is a quoted string"');
Cache::write('App.singleQuoteTest', "'this is a quoted string'");
$this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'");
Cache::engine('File', array('isWindows' => true, 'path' => TMP . 'tests'));
$this->assertIdentical(Cache::read('App.doubleQuoteTest'), '"this is a quoted string"');
Cache::write('App.singleQuoteTest', "'this is a quoted string'");
$this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'");
}
示例6: testExpiry
/**
* testExpiry method
*
* @access public
* @return void
*/
function testExpiry()
{
sleep(2);
$result = Cache::read('test');
$this->assertFalse($result);
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('other_test', $data, 1);
$this->assertTrue($result);
sleep(2);
$result = Cache::read('other_test');
$this->assertFalse($result);
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('other_test', $data, "+1 second");
$this->assertTrue($result);
sleep(2);
$result = Cache::read('other_test');
$this->assertFalse($result);
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('other_test', $data);
$this->assertTrue($result);
$result = Cache::read('other_test');
$this->assertEqual($result, $data);
Cache::engine('Memcache', array('duration' => '+1 second'));
sleep(2);
$result = Cache::read('other_test');
$this->assertFalse($result);
Cache::engine('Memcache', array('duration' => 3600));
}
示例7: testInitSettings
/**
* testInitSettings method
*
* @access public
* @return void
*/
function testInitSettings()
{
Cache::engine('File', array('path' => TMP . 'tests'));
$settings = Cache::settings();
$expecting = array('engine' => 'File', 'duration' => 3600, 'probability' => 100, 'path' => TMP . 'tests', 'prefix' => 'cake_', 'lock' => false, 'serialize' => true, 'isWindows' => DIRECTORY_SEPARATOR == '\\');
$this->assertEqual($settings, $expecting);
Cache::engine('File');
}
示例8: load
/**
Load and configure backend; Auto-detect if argument is FALSE
@return string|void
@param $dsn string|FALSE
**/
static function load($dsn = FALSE)
{
if (is_bool($dsn)) {
// Auto-detect backend
$ext = array_map('strtolower', get_loaded_extensions());
$grep = preg_grep('/^(apc|xcache|shmop)/', $ext);
$dsn = $grep ? current($grep) : 'folder=cache/';
}
$parts = explode('=', $dsn);
if (!preg_match('/apc|xcache|shmop|folder|memcache/', $parts[0])) {
return;
}
self::$engine = array('type' => $parts[0], 'data' => NULL);
self::$ref = NULL;
if ($parts[0] == 'shmop') {
$self = __CLASS__;
self::$ref = self::mutex(function () use($self) {
$ref = @shmop_open($ftok = ftok(__FILE__, 'C'), 'c', 0644, $self::bytes(ini_get('memory_limit')));
if ($ref && !unserialize(trim(shmop_read($ref, 0, 0xffff)))) {
shmop_write($ref, serialize(array()) . chr(0), 0);
}
return $ref;
}, self::$vars['TEMP'] . $_SERVER['SERVER_NAME']);
if (!self::$ref) {
return self::load('folder=cache/');
}
} elseif (isset($parts[1])) {
if ($parts[0] == 'memcache') {
if (extension_loaded('memcache')) {
foreach (self::split($parts[1]) as $server) {
$parts = explode(':', $server);
if (count($parts) < 2) {
$host = $parts[0];
$port = 11211;
} else {
list($host, $port) = $parts;
}
if (!self::$ref) {
self::$ref = @memcache_connect($host, $port);
} else {
memcache_add_server(self::$ref, $host, $port);
}
}
} else {
return self::$engine = NULL;
}
} elseif ($parts[0] == 'folder') {
if (!is_dir($parts[1]) && !@mkdir($parts[1], 0755, TRUE)) {
return self::$engine = NULL;
}
self::$ref = $parts[1];
}
}
return $dsn;
}
示例9: testWriteEmptyValues
/**
* testWriteEmptyValues method
*
* @access public
* @return void
*/
function testWriteEmptyValues()
{
return;
Cache::engine('File', array('path' => TMP . 'tests'));
Cache::write('App.falseTest', false);
$this->assertIdentical(Cache::read('App.falseTest'), false);
Cache::write('App.trueTest', true);
$this->assertIdentical(Cache::read('App.trueTest'), true);
Cache::write('App.nullTest', null);
$this->assertIdentical(Cache::read('App.nullTest'), null);
Cache::write('App.zeroTest', 0);
$this->assertIdentical(Cache::read('App.zeroTest'), 0);
Cache::write('App.zeroTest2', '0');
$this->assertIdentical(Cache::read('App.zeroTest2'), '0');
}
示例10: testEngineFailure
/**
* Test engine method.
*
* Failure.
*
* @return void
*/
public function testEngineFailure()
{
$actual = Cache::engine('some_config_that_does_not_exist');
$this->assertNull($actual);
Configure::write('Cache.disable', true);
$actual = Cache::engine();
$this->assertNull($actual);
}
示例11: testClear
function testClear()
{
$data = 'this is a test of the emergency broadcasting system';
$write = Cache::write('seriailze_test1', $data, 1);
$write = Cache::write('seriailze_test2', $data, 1);
$write = Cache::write('seriailze_test3', $data, 1);
$this->assertTrue(file_exists(CACHE . 'cake_seriailze_test1'));
$this->assertTrue(file_exists(CACHE . 'cake_seriailze_test2'));
$this->assertTrue(file_exists(CACHE . 'cake_seriailze_test3'));
Cache::engine('File', array('duration' => 1));
sleep(4);
$result = Cache::clear(true);
$this->assertTrue($result);
$this->assertFalse(file_exists(CACHE . 'cake_seriailze_test1'));
$this->assertFalse(file_exists(CACHE . 'cake_seriailze_test2'));
$this->assertFalse(file_exists(CACHE . 'cake_seriailze_test3'));
$data = 'this is a test of the emergency broadcasting system';
$write = Cache::write('seriailze_test1', $data, 1);
$write = Cache::write('seriailze_test2', $data, 1);
$write = Cache::write('seriailze_test3', $data, 1);
$this->assertTrue(file_exists(CACHE . 'cake_seriailze_test1'));
$this->assertTrue(file_exists(CACHE . 'cake_seriailze_test2'));
$this->assertTrue(file_exists(CACHE . 'cake_seriailze_test3'));
$result = Cache::clear();
$this->assertTrue($result);
$this->assertFalse(file_exists(CACHE . 'cake_seriailze_test1'));
$this->assertFalse(file_exists(CACHE . 'cake_seriailze_test2'));
$this->assertFalse(file_exists(CACHE . 'cake_seriailze_test3'));
}