本文整理汇总了PHP中Cake\Cache\Cache::increment方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::increment方法的具体用法?PHP Cache::increment怎么用?PHP Cache::increment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Cache\Cache
的用法示例。
在下文中一共展示了Cache::increment方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _touch
protected function _touch(Request $request)
{
$key = $this->config('identifier');
if (is_callable($key)) {
$key = $key($request);
}
return Cache::increment($key, static::$cacheConfig);
}
示例2: testGroupReadWrite
/**
* Tests that configuring groups for stored keys return the correct values when read/written
* Shows that altering the group value is equivalent to deleting all keys under the same
* group
*
* @return void
*/
public function testGroupReadWrite()
{
Cache::config('memcached_groups', ['engine' => 'Memcached', 'duration' => 3600, 'groups' => ['group_a', 'group_b'], 'prefix' => 'test_']);
Cache::config('memcached_helper', ['engine' => 'Memcached', 'duration' => 3600, 'prefix' => 'test_']);
$this->assertTrue(Cache::write('test_groups', 'value', 'memcached_groups'));
$this->assertEquals('value', Cache::read('test_groups', 'memcached_groups'));
Cache::increment('group_a', 1, 'memcached_helper');
$this->assertFalse(Cache::read('test_groups', 'memcached_groups'));
$this->assertTrue(Cache::write('test_groups', 'value2', 'memcached_groups'));
$this->assertEquals('value2', Cache::read('test_groups', 'memcached_groups'));
Cache::increment('group_b', 1, 'memcached_helper');
$this->assertFalse(Cache::read('test_groups', 'memcached_groups'));
$this->assertTrue(Cache::write('test_groups', 'value3', 'memcached_groups'));
$this->assertEquals('value3', Cache::read('test_groups', 'memcached_groups'));
}
示例3: testIncrement
/**
* testIncrement method
*
* @return void
*/
public function testIncrement()
{
$this->skipIf(!function_exists('apc_inc'), 'No apc_inc() function, cannot test increment().');
$result = Cache::write('test_increment', 5, 'apc');
$this->assertTrue($result);
$result = Cache::increment('test_increment', 1, 'apc');
$this->assertEquals(6, $result);
$result = Cache::read('test_increment', 'apc');
$this->assertEquals(6, $result);
$result = Cache::increment('test_increment', 2, 'apc');
$this->assertEquals(8, $result);
$result = Cache::read('test_increment', 'apc');
$this->assertEquals(8, $result);
}
示例4: testIncrementNonExistingConfig
/**
* Test write from a config that is undefined.
*
* @expectedException InvalidArgumentException
* @return void
*/
public function testIncrementNonExistingConfig()
{
$this->assertFalse(Cache::increment('key', 1, 'totally fake'));
}
示例5: testIncrement
/**
* testIncrement method
*
* @return void
*/
public function testIncrement()
{
$result = Cache::write('test_increment', 5, 'xcache');
$this->assertTrue($result);
$result = Cache::increment('test_increment', 'xcache');
$this->assertEquals(6, $result);
$result = Cache::read('test_increment', 'xcache');
$this->assertEquals(6, $result);
$result = Cache::increment('test_increment', 2, 'xcache');
$this->assertEquals(8, $result);
$result = Cache::read('test_increment', 'xcache');
$this->assertEquals(8, $result);
}
示例6: _touch
/**
* Atomically updates cache using default CakePHP increment offset 1.
*
* Please note that the cache key needs to be initialized to prevent
* increment() failing on 0. A separate cache key is created to store
* the interval expiration time in epoch.
*
* @return Cake\Cache\Cache
*/
protected function _touch()
{
if (Cache::read($this->_identifier, static::$cacheConfig) === false) {
Cache::write($this->_identifier, 0, static::$cacheConfig);
Cache::write($this->_getCacheExpirationKey(), strtotime($this->config('interval'), time()), static::$cacheConfig);
}
return Cache::increment($this->_identifier, 1, static::$cacheConfig);
}