本文整理汇总了PHP中apcu_store函数的典型用法代码示例。如果您正苦于以下问题:PHP apcu_store函数的具体用法?PHP apcu_store怎么用?PHP apcu_store使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了apcu_store函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
public function set($key, $value, $ttl)
{
if (is_array($key)) {
apcu_store($key, null, $ttl);
} else {
apcu_store($key, $value, $ttl);
}
}
示例2: storeItemInCache
protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
{
if ($ttl < 0) {
return false;
}
return apcu_store($key, $item->get(), $ttl);
}
示例3: set
/**
* Set a value to cache with id and lifetime
*
* $data = 'bar';
*
* // Set 'bar' to 'foo' in apc group, using default expiry
* Cache::instance('apc')->set('foo', $data);
*
* // Set 'bar' to 'foo' in apc group for 30 seconds
* Cache::instance('apc')->set('foo', $data, 30);
*
* @param string $id id of cache entry
* @param string $data data to set to cache
* @param integer $lifetime lifetime in seconds
* @return boolean
*/
public function set($id, $data, $lifetime = NULL)
{
if ($lifetime === NULL) {
$lifetime = $this->default_expire;
}
return \apcu_store($this->_sanitize_id($id), $data, $lifetime);
}
示例4: save
public function save($objectId, $object, $expiration = null)
{
$value = apcu_store($this->encode($this->apcNameSpace(), $objectId), $object, $expiration === null ? $this->expire() : $expiration);
if ($value === false) {
throw new WURFL_Storage_Exception("Error saving variable in APC cache. Cache may be full.");
}
}
示例5: store
public function store($key, $value)
{
if (apcu_store($key, $value)) {
apcu_inc('__known_apcu_size', strlen($value));
}
return false;
}
示例6: strongAdd
public function strongAdd(string $key, string $value, int $life = 3600) : bool
{
if ($life == 0) {
$life = null;
}
return apcu_store($key, $value, $life);
}
示例7: cacheStore
/**
* @param string $key
* @param mixed $item
* @return bool
*/
protected static function cacheStore($key, $item)
{
if (self::apcuExists()) {
return apcu_store($key, $item);
}
return false;
}
示例8: 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'));
}
示例9: apc_store
/**
* apcu library 5.x for php 7 have no more functions apc_*
* Uses apcu_* instead
*/
public static function apc_store($key, $var, $ttl)
{
if (self::isPhp7()) {
return apcu_store($key, $var, $ttl);
} else {
return apc_store($key, $var, $ttl);
}
}
示例10: store
/**
* Store the value in the apc memory
*
* @false string $key
* @false mix $value
* @param $key
* @param $value
* @throws \Exception
* @return bool
*/
public function store($key, $value, $minute = null)
{
if (is_null($key) || $key == "") {
throw new \InvalidArgumentException("Key shouldn't be empty");
}
$time = is_null($minute) ? $this->getLifeTime() : $minute * 60;
return $this->isApcUEnabled ? apcu_store($key, $value, $time) : apc_store($key, $value, $time);
}
示例11: testAPCUIterator
public function testAPCUIterator()
{
$key = __CLASS__;
$this->assertTrue(apcu_store($key, 456));
$entries = iterator_to_array(new \APCUIterator('/^' . preg_quote($key, '/') . '$/', APC_ITER_KEY | APC_ITER_VALUE));
$this->assertSame(array($key), array_keys($entries));
$this->assertSame($key, $entries[$key]['key']);
$this->assertSame(456, $entries[$key]['value']);
}
示例12: put
/**
* Put a key/value set in the cache.
* @see apc_store()
*
* @param mixed $key
* @param mixed $value
* @param integer $ttl (in seconds)
*
* @return boolean
*/
public function put($key, $value, $ttl = 0)
{
if (function_exists('apcu_store')) {
return apcu_store($key, $value, $ttl);
} elseif (function_exists('apc_store')) {
return apc_store($key, $value, $ttl);
}
return false;
}
示例13: store
public static function store($k, $v, $ttl = 300)
{
if (function_exists('apc_store')) {
return apc_store($k, $v, $ttl);
} elseif (function_exists('apcu_store')) {
return apcu_store($k, $v, $ttl);
}
return false;
}
示例14: set
public function set($name, $value, $ttl = 0)
{
if ($this->hasAPCu) {
apcu_store($name, $value, $ttl);
} else {
$_SESSION[$name] = $value;
}
return true;
}
示例15: setDataStore
public function setDataStore($key, $data, $timeCache = null)
{
if (!empty($timeCache)) {
apcu_store($key, $data, $timeCache);
} else {
apcu_store($key, $data, $this->timeCache);
}
return true;
}