Skip to content

Commit

Permalink
Update ApcEngine & tests for Cache changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 18, 2012
1 parent fbf401f commit 4f325a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
14 changes: 4 additions & 10 deletions lib/Cake/Cache/Engine/ApcEngine.php
@@ -1,10 +1,5 @@
<?php
/**
* APC storage engine for cache.
*
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -18,6 +13,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Cache\Engine;

use Cake\Cache\CacheEngine;
use Cake\Utility\Inflector;

Expand All @@ -30,7 +26,7 @@ class ApcEngine extends CacheEngine {

/**
* Contains the compiled group names
* (prefixed witht the global configuration prefix)
* (prefixed with the global configuration prefix)
*
* @var array
**/
Expand All @@ -40,11 +36,9 @@ class ApcEngine extends CacheEngine {
* Initialize the Cache Engine
*
* Called automatically by the cache frontend
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
* @return boolean True if the engine has been successfully initialized, false if not
* @see CacheEngine::__defaults
*/
public function init($settings = array()) {
if (!isset($settings['prefix'])) {
Expand Down Expand Up @@ -148,7 +142,7 @@ public function clear($check) {
* the group accordingly.
*
* @return array
**/
*/
public function groups() {
if (empty($this->_compiledGroupNames)) {
foreach ($this->settings['groups'] as $group) {
Expand Down Expand Up @@ -180,7 +174,7 @@ public function groups() {
* old values will remain in storage until they expire.
*
* @return boolean success
**/
*/
public function clearGroup($group) {
apc_inc($this->settings['prefix'] . $group, 1, $success);
return $success;
Expand Down
29 changes: 12 additions & 17 deletions lib/Cake/Test/TestCase/Cache/Engine/ApcEngineTest.php
@@ -1,10 +1,6 @@
<?php
/**
* ApcEngineTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* CakePHP(tm) <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
Expand All @@ -17,6 +13,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\Cache\Engine;

use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\TestSuite\TestCase;
Expand All @@ -37,9 +34,8 @@ public function setUp() {
parent::setUp();
$this->skipIf(!function_exists('apc_store'), 'Apc is not installed or configured properly.');

$this->_cacheDisable = Configure::read('Cache.disable');
Configure::write('Cache.disable', false);
Cache::config('apc', array('engine' => 'Apc', 'prefix' => 'cake_'));
Configure::write('Cache.apc', ['engine' => 'Apc', 'prefix' => 'cake_']);
}

/**
Expand All @@ -49,10 +45,8 @@ public function setUp() {
*/
public function tearDown() {
parent::tearDown();
Configure::write('Cache.disable', $this->_cacheDisable);
Cache::drop('apc');
Cache::drop('apc_groups');
Cache::config('default');
}

/**
Expand All @@ -61,7 +55,7 @@ public function tearDown() {
* @return void
*/
public function testReadAndWriteCache() {
Cache::set(array('duration' => 1), 'apc');
Cache::set(['duration' => 1], 'apc');

$result = Cache::read('test', 'apc');
$expecting = '';
Expand All @@ -84,7 +78,7 @@ public function testReadAndWriteCache() {
* @return void
*/
public function testReadWriteDurationZero() {
Cache::config('apc', array('engine' => 'Apc', 'duration' => 0, 'prefix' => 'cake_'));
Configure::write('apc', ['engine' => 'Apc', 'duration' => 0, 'prefix' => 'cake_']);
Cache::write('zero', 'Should save', 'apc');
sleep(1);

Expand All @@ -98,7 +92,7 @@ public function testReadWriteDurationZero() {
* @return void
*/
public function testExpiry() {
Cache::set(array('duration' => 1), 'apc');
Cache::set(['duration' => 1], 'apc');

$result = Cache::read('test', 'apc');
$this->assertFalse($result);
Expand All @@ -111,7 +105,7 @@ public function testExpiry() {
$result = Cache::read('other_test', 'apc');
$this->assertFalse($result);

Cache::set(array('duration' => 1), 'apc');
Cache::set(['duration' => 1], 'apc');

$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('other_test', $data, 'apc');
Expand Down Expand Up @@ -212,12 +206,12 @@ public function testClear() {
* @return void
*/
public function testGroupsReadWrite() {
Cache::config('apc_groups', array(
Configure::write('Cache.apc_groups', [
'engine' => 'Apc',
'duration' => 0,
'groups' => array('group_a', 'group_b'),
'prefix' => 'test_'
));
]);
$this->assertTrue(Cache::write('test_groups', 'value', 'apc_groups'));
$this->assertEquals('value', Cache::read('test_groups', 'apc_groups'));

Expand All @@ -238,7 +232,7 @@ public function testGroupsReadWrite() {
* @return void
*/
public function testGroupDelete() {
Cache::config('apc_groups', array(
Configure::write('Cache.apc_groups', array(
'engine' => 'Apc',
'duration' => 0,
'groups' => array('group_a', 'group_b'),
Expand All @@ -257,7 +251,7 @@ public function testGroupDelete() {
* @return void
**/
public function testGroupClear() {
Cache::config('apc_groups', array(
Configure::write('Cache.apc_groups', array(
'engine' => 'Apc',
'duration' => 0,
'groups' => array('group_a', 'group_b'),
Expand All @@ -272,4 +266,5 @@ public function testGroupClear() {
$this->assertTrue(Cache::clearGroup('group_b', 'apc_groups'));
$this->assertFalse(Cache::read('test_groups', 'apc_groups'));
}

}

0 comments on commit 4f325a7

Please sign in to comment.