本文整理汇总了PHP中apcu_exists函数的典型用法代码示例。如果您正苦于以下问题:PHP apcu_exists函数的具体用法?PHP apcu_exists怎么用?PHP apcu_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了apcu_exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetch
public function fetch($key)
{
if (apcu_exists($key)) {
return apcu_fetch($key);
}
return false;
}
示例2: has
/**
* {@inheritdoc}
*/
public function has($key)
{
if (!apcu_exists($key)) {
return false;
}
return true;
}
示例3: has
/**
* {@inheritdoc}
*/
public function has($name)
{
if ($this->driver == self::APCU_DRIVER) {
return apcu_exists($this->prefix . $name);
}
return apc_exists($this->prefix . $name);
}
示例4: fetch
public function fetch($key, $default = '')
{
if (!apcu_exists($this->hash($key))) {
return $default;
}
return apcu_fetch($this->hash($key));
}
示例5: test_purge
/**
* Test purging the apcu cache store.
*/
public function test_purge()
{
if (!cachestore_apcu::are_requirements_met()) {
$this->markTestSkipped('Could not test cachestore_apcu. Requirements are not met.');
}
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test');
$instance = cachestore_apcu::initialise_unit_test_instance($definition);
// Test a simple purge return.
$this->assertTrue($instance->purge());
// Test purge works.
$this->assertTrue($instance->set('test', 'monster'));
$this->assertSame('monster', $instance->get('test'));
$this->assertTrue($instance->purge());
$this->assertFalse($instance->get('test'));
// Test purge with custom data.
$this->assertTrue($instance->set('test', 'monster'));
$this->assertSame('monster', $instance->get('test'));
$this->assertTrue(apcu_store('test', 'pirate', 180));
$this->assertSame('monster', $instance->get('test'));
$this->assertTrue(apcu_exists('test'));
$this->assertSame('pirate', apcu_fetch('test'));
// Purge and check that our data is gone but the the custom data is still there.
$this->assertTrue($instance->purge());
$this->assertFalse($instance->get('test'));
$this->assertTrue(apcu_exists('test'));
$this->assertSame('pirate', apcu_fetch('test'));
}
示例6: has
public function has($key)
{
if ($this->apcu) {
return apcu_exists((string) $key);
}
return apc_exists((string) $key);
}
示例7: read
public function read()
{
if (!apcu_exists($this->key)) {
return array('_global' => array());
}
return apcu_fetch($this->key);
}
示例8: cacheHas
/**
* @param string $key
* @return bool
*/
protected static function cacheHas($key)
{
if (self::apcuExists()) {
return apcu_exists($key);
}
return false;
}
示例9: increment
public static function increment($host)
{
if (!apcu_exists(self::$prefix . $host)) {
apcu_store(self::$prefix . $host, 0, self::$ttl);
}
apcu_inc(self::$prefix . $host);
return apcu_fetch(self::$prefix . $host);
}
示例10: exist
public function exist($name)
{
if ($this->hasAPCu) {
return apcu_exists($name);
} else {
return isset($_SESSION[$name]);
}
}
示例11: exists
public static function exists($k)
{
if (function_exists('apc_exists')) {
return apc_exists($k);
} elseif (function_exists('apcu_exists')) {
return apcu_exists($k);
}
return false;
}
示例12: getHandlers
public function getHandlers()
{
$key = $this->_mapTags($this->_handlers_name, 0);
if (apcu_exists($key)) {
$result = apcu_fetch($key);
return $result;
}
return array();
}
示例13: has
/**
* {@inheritdoc }
*/
public function has($key)
{
$tKey = $this->getKey($key);
if (function_exists("\\apcu_exists") || function_exists("\\apc_exists")) {
return (bool) ($this->apcu ? \apcu_exists($tKey) : \apc_exists($tKey));
} else {
$result = false;
$this->apcu ? \apcu_fetch($tKey, $result) : \apc_fetch($tKey, $result);
return (bool) $result;
}
}
示例14: decr
public function decr($key, $value = 1)
{
/**
* @todo When we only support php 7 or higher remove this hack
*
* https://github.com/krakjoe/apcu/issues/166
*/
if (apcu_exists($key . self::KEY_SUFFIX)) {
return apcu_dec($key . self::KEY_SUFFIX, $value);
} else {
return apcu_set($key . self::KEY_SUFFIX, -$value);
}
}
示例15: test_cross_application_interaction
/**
* Test that the Moodle APCu store doesn't cross paths with other code using APCu as well.
*/
public function test_cross_application_interaction()
{
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test');
$instance = cachestore_apcu::initialise_unit_test_instance($definition);
// Test purge with custom data.
$this->assertTrue($instance->set('test', 'monster'));
$this->assertSame('monster', $instance->get('test'));
$this->assertTrue(apcu_store('test', 'pirate', 180));
$this->assertSame('monster', $instance->get('test'));
$this->assertTrue(apcu_exists('test'));
$this->assertSame('pirate', apcu_fetch('test'));
// Purge and check that our data is gone but the the custom data is still there.
$this->assertTrue($instance->purge());
$this->assertFalse($instance->get('test'));
$this->assertTrue(apcu_exists('test'));
$this->assertSame('pirate', apcu_fetch('test'));
}