class MemCacheGetMultipleUnitTest in Memcache API and Integration 7
Test cache_get_multiple().
Hierarchy
- class \MemCacheGetMultipleUnitTest extends \MemcacheTestCase
Expanded class hierarchy of MemCacheGetMultipleUnitTest
File
- tests/
memcache.test, line 369 - Test cases for the memcache cache backend.
View source
class MemCacheGetMultipleUnitTest extends MemcacheTestCase {
public static function getInfo() {
return array(
'name' => 'Fetching multiple cache items',
'description' => 'Confirm that multiple records are fetched correctly.',
'group' => 'Memcache',
);
}
/**
* @see MemcacheTestCase::setUp()
*/
function setUp() {
parent::setUp();
}
/**
* Test cache_get_multiple().
*/
public function testCacheMultiple() {
$item1 = $this
->randomName(10);
$item2 = $this
->randomName(10);
cache_set('test:item1', $item1, $this->default_bin);
cache_set('test:item2', $item2, $this->default_bin);
$this
->assertTrue($this
->checkCacheExists('test:item1', $item1), t('Item 1 is cached.'));
$this
->assertTrue($this
->checkCacheExists('test:item2', $item2), t('Item 2 is cached.'));
// Fetch both records from the database with cache_get_multiple().
$item_ids = array(
'test:item1',
'test:item2',
);
$items = cache_get_multiple($item_ids, $this->default_bin);
$this
->assertEqual($items['test:item1']->data, $item1, t('Item was returned from cache successfully.'));
$this
->assertEqual($items['test:item2']->data, $item2, t('Item was returned from cache successfully.'));
$this
->assertTrue(empty($item_ids), t('Ids of returned items have been removed.'));
// Remove one item from the cache.
cache_clear_all('test:item2', $this->default_bin);
// Confirm that only one item is returned by cache_get_multiple().
$item_ids = array(
'test:item1',
'test:item2',
);
$items = cache_get_multiple($item_ids, $this->default_bin);
$this
->assertEqual($items['test:item1']->data, $item1, t('Item was returned from cache successfully.'));
$this
->assertFalse(isset($items['test:item2']), t('Item was not returned from the cache.'));
$this
->assertTrue(count($items) == 1, t('Only valid cache entries returned.'));
$this
->assertTrue(count($item_ids) == 1, t('Invalid cache ids still present.'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MemCacheGetMultipleUnitTest:: |
public static | function | ||
MemCacheGetMultipleUnitTest:: |
function | |||
MemCacheGetMultipleUnitTest:: |
public | function | Test cache_get_multiple(). |