Skip to content
Permalink
Browse files

Remove Cache.disable from Configure.

Give it a set of named methods on Cache. This configure value always
felt out of place and fits much better with Cache's feature set.
  • Loading branch information...
markstory committed Aug 17, 2013
1 parent b1a2f86 commit 7cf790174a15d9716bb41eae707edb89e56864a9
@@ -21,7 +21,7 @@
* Turn off all caching application-wide.
*
*/
//Configure::write('Cache.disable', true);
// Cache::disable();
/**
* Enable cache checking.
@@ -82,6 +82,13 @@
*/
class Cache {
/**
* Flag for tracking whether or not caching is enabled.
*
* @var boolean
*/
protected static $_enabled = true;
/**
* Configuraiton backup.
*
@@ -221,8 +228,8 @@ public static function configured() {
/**
* Drops a constructed cache engine.
*
* The engine's configuration will remain in Configure. If you wish to re-configure a
* cache engine you should drop it, change configuration and then re-use it.
* If you wish to re-configure a cache engine you should drop it,
* change configuration and then re-use it.
*
* @param string $config A currently configured cache config you wish to remove.
* @return boolean success of the removal, returns false when the config does not exist.
@@ -245,7 +252,7 @@ public static function drop($config) {
* @return Cake\Cache\Engine
*/
public static function engine($config) {
if (Configure::read('Cache.disable')) {
if (!static::$_enabled) {
return false;
}
@@ -594,4 +601,35 @@ public static function groupConfigs($group = null) {
throw new Error\Exception(__d('cake_dev', 'Invalid cache group %s', $group));
}
/**
* Re-enable caching.
*
* If caching has been disabled with Cache::disable() this method will reverse that effect.
*
* @return void
*/
public static function enable() {
static::$_enabled = true;
}
/**
* Disable caching.
*
* When disabled all cache operations will return null.
*
* @return void
*/
public static function disable() {
static::$_enabled = false;
}
/**
* Check whether or not caching is enabled.
*
* @return boolean
*/
public static function enabled() {
return static::$_enabled;
}
}
@@ -15,6 +15,7 @@
namespace Cake\Console\Command;
use Cake\Console\Shell;
use Cake\Cache\Cache;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Model\Model;
@@ -54,7 +55,7 @@ class BakeShell extends Shell {
public function startup() {
parent::startup();
Configure::write('debug', 2);
Configure::write('Cache.disable', 1);
Cache::disable();
$task = Inflector::classify($this->command);
if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) {
@@ -15,6 +15,7 @@
namespace Cake\Console\Command;
use Cake\Console\Shell;
use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\Model\ConnectionManager;
use Cake\Model\Schema;
@@ -60,7 +61,7 @@ public function startup() {
throw new \Cake\Error\Exception('Schema shell is not working at this time.');
Configure::write('Cache.disable', 1);
Cache::disable();
$name = $path = $connection = $plugin = null;
if (!empty($this->params['name'])) {
@@ -152,13 +153,12 @@ public function generate() {
}
}
$cacheDisable = Configure::read('Cache.disable');
Configure::write('Cache.disable', true);
Cache::enable();
$content = $this->Schema->read($options);
$content['file'] = $this->params['file'];
Configure::write('Cache.disable', $cacheDisable);
Cache::disable();
if (!empty($this->params['exclude']) && !empty($content)) {
$excluded = String::tokenize($this->params['exclude']);
@@ -19,6 +19,7 @@
namespace Cake\Console\Command\Task;
use Cake\Console\Shell;
use Cake\Cache\Cache;
use Cake\Core\Configure;
/**
@@ -57,7 +58,7 @@ class BakeTask extends Shell {
*/
public function startup() {
Configure::write('debug', 2);
Configure::write('Cache.disable', 1);
Cache::disable();
parent::startup();
}
@@ -20,7 +20,7 @@
* Turn off all caching application-wide.
*
*/
//Configure::write('Cache.disable', true);
// Cache::disable();
/**
* Enable cache checking.
@@ -19,6 +19,7 @@
*/
namespace Cake\Test\TestCase;
use Cake\Cache\Cache;
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Log\Log;
@@ -281,17 +282,14 @@ public function testAm() {
* @return void
*/
public function testCache() {
$_cacheDisable = Configure::read('Cache.disable');
$this->skipIf($_cacheDisable, 'Cache is disabled, skipping cache() tests.');
Configure::write('Cache.disable', true);
Cache::disable();
$result = cache('basics_test', 'simple cache write');
$this->assertNull($result);
$result = cache('basics_test');
$this->assertNull($result);
Configure::write('Cache.disable', false);
Cache::enable();
$result = cache('basics_test', 'simple cache write');
$this->assertTrue((boolean)$result);
$this->assertTrue(file_exists(CACHE . 'basics_test'));
@@ -306,8 +304,6 @@ public function testCache() {
sleep(2);
$result = cache('basics_test', null, '+1 second');
$this->assertNull($result);
Configure::write('Cache.disable', $_cacheDisable);
}
/**
@@ -35,7 +35,7 @@ class CacheTest extends TestCase {
*/
public function setUp() {
parent::setUp();
Configure::write('Cache.disable', false);
Cache::enable();
}
/**
@@ -62,7 +62,7 @@ protected function _configCache() {
* @return void
*/
public function testNonFatalErrorsWithCachedisable() {
Configure::write('Cache.disable', true);
Cache::disable();
$this->_configCache();
Cache::write('no_save', 'Noooo!', 'tests');
@@ -378,7 +378,7 @@ public function testWriteTriggerError() {
* @return void
*/
public function testCacheDisable() {
Configure::write('Cache.disable', false);
Cache::enable();
Cache::config('test_cache_disable_1', [
'engine' => 'File',
'path' => TMP . 'tests'
@@ -387,17 +387,17 @@ public function testCacheDisable() {
$this->assertTrue(Cache::write('key_1', 'hello', 'test_cache_disable_1'));
$this->assertSame(Cache::read('key_1', 'test_cache_disable_1'), 'hello');
Configure::write('Cache.disable', true);
Cache::disable();
$this->assertFalse(Cache::write('key_2', 'hello', 'test_cache_disable_1'));
$this->assertFalse(Cache::read('key_2', 'test_cache_disable_1'));
Configure::write('Cache.disable', false);
Cache::enable();
$this->assertTrue(Cache::write('key_3', 'hello', 'test_cache_disable_1'));
$this->assertSame(Cache::read('key_3', 'test_cache_disable_1'), 'hello');
Configure::write('Cache.disable', true);
Cache::disable();
Cache::config('test_cache_disable_2', [
'engine' => 'File',
'path' => TMP . 'tests'
@@ -406,12 +406,12 @@ public function testCacheDisable() {
$this->assertFalse(Cache::write('key_4', 'hello', 'test_cache_disable_2'));
$this->assertFalse(Cache::read('key_4', 'test_cache_disable_2'));
Configure::write('Cache.disable', false);
Cache::enable();
$this->assertTrue(Cache::write('key_5', 'hello', 'test_cache_disable_2'));
$this->assertSame(Cache::read('key_5', 'test_cache_disable_2'), 'hello');
Configure::write('Cache.disable', true);
Cache::disable();
$this->assertFalse(Cache::write('key_6', 'hello', 'test_cache_disable_2'));
$this->assertFalse(Cache::read('key_6', 'test_cache_disable_2'));
@@ -42,7 +42,7 @@ public function setUp() {
$this->skipIf(!ini_get('apc.enable_cli'), 'APC is not enabled for the CLI.');
}
Configure::write('Cache.disable', false);
Cache::enable();
Cache::config('apc', ['engine' => 'Apc', 'prefix' => 'cake_']);
}
@@ -44,7 +44,7 @@ class FileEngineTest extends TestCase {
*/
public function setUp() {
parent::setUp();
Configure::write('Cache.disable', false);
Cache::enable();
Cache::config('file_test', [
'engine' => 'File',
'path' => TMP . 'tests',
@@ -61,7 +61,7 @@ public function setUp() {
parent::setUp();
$this->skipIf(!class_exists('Memcache'), 'Memcache is not installed or configured properly.');
Configure::write('Cache.disable', false);
Cache::enable();
Cache::config('memcache', array(
'className' => 'Memcache',
'prefix' => 'cake_',
@@ -35,7 +35,7 @@ public function setUp() {
parent::setUp();
$this->skipIf(!class_exists('Redis'), 'Redis is not installed or configured properly.');
Configure::write('Cache.disable', false);
Cache::enable();
Cache::config('redis', array(
'engine' => 'Cake\Cache\Engine\RedisEngine',
'prefix' => 'cake_',
@@ -38,7 +38,7 @@ class WincacheEngineTest extends TestCase {
public function setUp() {
parent::setUp();
$this->skipIf(!function_exists('wincache_ucache_set'), 'Wincache is not installed or configured properly.');
Configure::write('Cache.disable', false);
Cache::enable();
Cache::config('wincache', ['engine' => 'Wincache', 'prefix' => 'cake_']);
}
@@ -39,7 +39,7 @@ public function setUp() {
if (!function_exists('xcache_set')) {
$this->markTestSkipped('Xcache is not installed or configured properly');
}
Configure::write('Cache.disable', false);
Cache::enable();
Cache::config('xcache', ['engine' => 'Xcache', 'prefix' => 'cake_']);
}
@@ -42,7 +42,7 @@ class ConfigureTest extends TestCase {
*/
public function setUp() {
parent::setUp();
Configure::write('Cache.disable', true);
Cache::disable();
App::build();
App::objects('Plugin', null, true);
}
@@ -339,7 +339,7 @@ public function testLoadPlugin() {
* @return void
*/
public function testStoreAndRestore() {
Configure::write('Cache.disable', false);
Cache::enable();
Cache::config('configure', [
'className' => 'File',
'path' => TMP . 'tests'
@@ -364,7 +364,7 @@ public function testStoreAndRestore() {
* @return void
*/
public function testStoreAndRestoreWithData() {
Configure::write('Cache.disable', false);
Cache::enable();
Cache::config('configure', [
'className' => 'File',
'path' => TMP . 'tests'
@@ -260,12 +260,8 @@ public function testAllowSimulatedFields() {
* @return void
*/
public function testCacheClearOnSave() {
$_back = array(
'check' => Configure::read('Cache.check'),
'disable' => Configure::read('Cache.disable'),
);
Configure::write('Cache.check', true);
Configure::write('Cache.disable', false);
Cache::enable();
$this->loadFixtures('OverallFavorite');
$OverallFavorite = new OverallFavorite();
@@ -286,9 +282,6 @@ public function testCacheClearOnSave() {
$this->assertFalse(file_exists(CACHE . 'views/some_dir_overallfavorites_index.php'));
$this->assertFalse(file_exists(CACHE . 'views/some_dir_overall_favorites_index.php'));
Configure::write('Cache.check', $_back['check']);
Configure::write('Cache.disable', $_back['disable']);
}
/**
@@ -18,6 +18,7 @@
*/
namespace Cake\Test\TestCase\Routing;
use Cake\Cache\Cache;
use Cake\Controller\Controller;
use Cake\Core\App;
use Cake\Core\Configure;
@@ -266,17 +267,13 @@ public function setUp() {
parent::setUp();
$_GET = array();
$this->_app = Configure::read('App');
Configure::write('App.base', false);
Configure::write('App.baseUrl', false);
Configure::write('App.dir', 'app');
Configure::write('App.webroot', 'webroot');
Configure::write('App.namespace', 'TestApp');
$this->_cache = Configure::read('Cache');
Configure::write('Cache.disable', true);
$this->_debug = Configure::read('debug');
Cache::disable();
App::build();
App::objects('Plugin', null, false);
@@ -944,6 +941,7 @@ public static function cacheActionProvider() {
* @return void
*/
public function testFullPageCachingDispatch($url) {
Cache::enable();
Configure::write('Cache.disable', false);
Configure::write('Cache.check', true);
Configure::write('debug', 2);
Oops, something went wrong.

0 comments on commit 7cf7901

Please sign in to comment.
You can’t perform that action at this time.