Making locking file caching the default.

Locking files prevents many issues with unserialize() warnings
caused by partially written files.
Fix a locking issue where files would be left locked.
Fixes #1988
This commit is contained in:
mark_story 2011-09-25 09:26:32 -04:00
parent b1dad6e5bd
commit 79687a2dcf
2 changed files with 5 additions and 2 deletions

View file

@ -66,7 +66,7 @@ class FileEngine extends CacheEngine {
public function init($settings = array()) {
parent::init(array_merge(
array(
'engine' => 'File', 'path' => CACHE, 'prefix'=> 'cake_', 'lock'=> false,
'engine' => 'File', 'path' => CACHE, 'prefix'=> 'cake_', 'lock'=> true,
'serialize'=> true, 'isWindows' => false
),
$settings
@ -162,6 +162,9 @@ class FileEngine extends CacheEngine {
$cachetime = intval($this->_File->current());
if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
if ($this->settings['lock']) {
$this->_File->flock(LOCK_UN);
}
return false;
}

View file

@ -197,7 +197,7 @@ class CacheTest extends CakeTestCase {
$expected = array(
'path' => TMP . 'sessions' . DS,
'prefix' => 'cake_',
'lock' => false,
'lock' => true,
'serialize' => true,
'duration' => 3600,
'probability' => 100,