Skip to content

Commit

Permalink
Merge branch '1.3-cache' into 1.3-misc
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 21, 2009
2 parents c115094 + d37dd4c commit a729fc4
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 273 deletions.
293 changes: 136 additions & 157 deletions cake/libs/cache.php

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions cake/libs/cache/file.php
Expand Up @@ -37,11 +37,12 @@ class FileEngine extends CacheEngine {
var $__File = null;

/**
* settings
* path = absolute path to cache directory, default => CACHE
* prefix = string prefix for filename, default => cake_
* lock = enable file locking on write, default => false
* serialize = serialize the data, default => true
* Settings
*
* - path = absolute path to cache directory, default => CACHE
* - prefix = string prefix for filename, default => cake_
* - lock = enable file locking on write, default => false
* - serialize = serialize the data, default => true
*
* @var array
* @see CacheEngine::__defaults
Expand Down
12 changes: 6 additions & 6 deletions cake/libs/cache/xcache.php
Expand Up @@ -2,7 +2,6 @@
/**
* Xcache storage engine for cache.
*
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
Expand All @@ -29,9 +28,10 @@
class XcacheEngine extends CacheEngine {

/**
* settings
* PHP_AUTH_USER = xcache.admin.user, default cake
* PHP_AUTH_PW = xcache.admin.password, default cake
* Settings
*
* - PHP_AUTH_USER = xcache.admin.user, default cake
* - PHP_AUTH_PW = xcache.admin.password, default cake
*
* @var array
* @access public
Expand Down Expand Up @@ -67,7 +67,7 @@ function init($settings) {
*/
function write($key, &$value, $duration) {
$expires = time() + $duration;
xcache_set($key.'_expires', $expires, $duration);
xcache_set($key . '_expires', $expires, $duration);
return xcache_set($key, $value, $duration);
}

Expand All @@ -81,7 +81,7 @@ function write($key, &$value, $duration) {
function read($key) {
if (xcache_isset($key)) {
$time = time();
$cachetime = intval(xcache_get($key.'_expires'));
$cachetime = intval(xcache_get($key . '_expires'));
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions cake/libs/log/file_log.php
Expand Up @@ -2,7 +2,6 @@
/**
* File Storage stream for Logging
*
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
Expand All @@ -18,7 +17,9 @@
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

if (!class_exists('File')) {
require LIBS . 'file.php';
}
/**
* File Storage stream for Logging
*
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/model/datasources/dbo/dbo_mssql.php
Expand Up @@ -426,7 +426,7 @@ function update(&$model, $fields = array(), $values = null, $conditions = null)
* @return string Error message with error number
*/
function lastError() {
$error = mssql_get_last_message($this->connection);
$error = mssql_get_last_message();

if ($error) {
if (!preg_match('/contexto de la base de datos a|contesto di database|changed database|datenbankkontext/i', $error)) {
Expand Down
1 change: 1 addition & 0 deletions cake/libs/router.php
Expand Up @@ -183,6 +183,7 @@ function __setPrefixes() {
$this->__prefixes = array_merge($this->__prefixes, (array)$routing['prefixes']);
}
}

/**
* Gets a reference to the Router object instance
*
Expand Down
4 changes: 1 addition & 3 deletions cake/libs/view/helpers/paginator.php
Expand Up @@ -302,9 +302,7 @@ function sort($title, $key = null, $options = array()) {
$isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key);

if ($isSorted) {
if ($this->sortDir($options['model']) === 'asc') {
$dir = 'desc';
}
$dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc';
$class = $dir === 'asc' ? 'desc' : 'asc';
if (!empty($options['class'])) {
$options['class'] .= $class;
Expand Down
50 changes: 38 additions & 12 deletions cake/tests/cases/libs/cache.test.php
Expand Up @@ -43,8 +43,6 @@ function setUp() {

$this->_defaultCacheConfig = Cache::config('default');
Cache::config('default', array('engine' => 'File', 'path' => TMP . 'tests'));

Cache::engine('File', array('path' => TMP . 'tests'));
}

/**
Expand All @@ -56,7 +54,6 @@ function setUp() {
function tearDown() {
Configure::write('Cache.disable', $this->_cacheDisable);
Cache::config('default', $this->_defaultCacheConfig['settings']);
Cache::engine('File');
}

/**
Expand Down Expand Up @@ -127,15 +124,45 @@ function testConfigChange() {
$_cacheConfigTests = Cache::config('tests');

$result = Cache::config('sessions', array('engine'=> 'File', 'path' => TMP . 'sessions'));
$this->assertEqual($result['settings'], Cache::settings('File'));
$this->assertEqual($result['settings'], Cache::settings('sessions'));

$result = Cache::config('tests', array('engine'=> 'File', 'path' => TMP . 'tests'));
$this->assertEqual($result['settings'], Cache::settings('File'));
$this->assertEqual($result['settings'], Cache::settings('tests'));

Cache::config('sessions', $_cacheConfigSessions['settings']);
Cache::config('tests', $_cacheConfigTests['settings']);
}

/**
* test that calling config() sets the 'default' configuration up.
*
* @return void
*/
function testConfigSettingDefaultConfigKey() {
Cache::config('test_name', array('engine' => 'File', 'prefix' => 'test_name_'));

Cache::config('test_name');
Cache::write('value_one', 'I am cached');
$result = Cache::read('value_one');
$this->assertEqual($result, 'I am cached');

Cache::config('default');
$result = Cache::read('value_one');
$this->assertEqual($result, null);

Cache::write('value_one', 'I am in another cache config!');
$result = Cache::read('value_one');
$this->assertEqual($result, 'I am in another cache config!');

Cache::config('test_name');
$result = Cache::read('value_one');
$this->assertEqual($result, 'I am cached');

Cache::delete('value_one');
Cache::config('default');
Cache::delete('value_one');
}

/**
* testWritingWithConfig method
*
Expand All @@ -157,7 +184,7 @@ function testWritingWithConfig() {
'engine' => 'File',
'isWindows' => DIRECTORY_SEPARATOR == '\\'
);
$this->assertEqual($expected, Cache::settings('File'));
$this->assertEqual($expected, Cache::settings('sessions'));

Cache::config('sessions', $_cacheConfigSessions['settings']);
}
Expand All @@ -181,7 +208,7 @@ function testConfigured() {
* @return void
*/
function testInitSettings() {
Cache::engine('File', array('path' => TMP . 'tests'));
Cache::config('default', array('engine' => 'File', 'path' => TMP . 'tests'));

$settings = Cache::settings();
$expecting = array(
Expand All @@ -195,17 +222,15 @@ function testInitSettings() {
'isWindows' => DIRECTORY_SEPARATOR == '\\'
);
$this->assertEqual($settings, $expecting);

Cache::engine('File');
}

/**
* test that unconfig removes cache configs, and that further attempts to use that config
* test that drop removes cache configs, and that further attempts to use that config
* do not work.
*
* @return void
*/
function testUnconfig() {
function testDrop() {
App::build(array(
'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS),
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
Expand All @@ -221,7 +246,7 @@ function testUnconfig() {
Cache::config('unconfigTest', array(
'engine' => 'TestAppCache'
));
$this->assertTrue(Cache::isInitialized('TestAppCache'));
$this->assertTrue(Cache::isInitialized('unconfigTest'));

$this->assertTrue(Cache::drop('unconfigTest'));
$this->assertFalse(Cache::isInitialized('TestAppCache'));
Expand Down Expand Up @@ -324,5 +349,6 @@ function testSet() {

Cache::set($_cacheSet);
}

}
?>
5 changes: 3 additions & 2 deletions cake/tests/cases/libs/cache/apc.test.php
Expand Up @@ -39,7 +39,7 @@ class ApcEngineTest extends UnitTestCase {
*/
function skip() {
$skip = true;
if (Cache::engine('Apc')) {
if (function_exists('apc_store')) {
$skip = false;
}
$this->skipIf($skip, '%s Apc is not installed or configured properly');
Expand All @@ -65,6 +65,7 @@ function setUp() {
*/
function tearDown() {
Configure::write('Cache.disable', $this->_cacheDisable);
Cache::drop('apc');
Cache::config('default');
}

Expand Down Expand Up @@ -112,7 +113,7 @@ function testExpiry() {
$result = Cache::read('other_test');
$this->assertFalse($result);

Cache::set(array('duration' => "+1 second"));
Cache::set(array('duration' => 1));

$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('other_test', $data);
Expand Down

0 comments on commit a729fc4

Please sign in to comment.