updating datasource to use Cache engines.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7037 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-05-24 02:08:56 +00:00
parent 060bbf1caf
commit 92514422e4
2 changed files with 26 additions and 21 deletions

View file

@ -642,16 +642,21 @@ class Configure extends Object {
$cache = Cache::config('default', array('engine' => 'File'));
}
$settings = array_merge($cache['settings'], array('prefix' => 'cake_core_', 'serialize' => true));
$coreCache = array_merge($cache['settings'], array('prefix' => 'cake_core_', 'serialize' => true));
$modelCache = array_merge($cache['settings'], array('prefix' => 'cake_model_', 'serialize' => true));
if (Configure::read() > 1) {
$settings['duration'] = 10;
$coreCache['duration'] = 10;
$modelCache['duration'] = 10;
}
if (!empty($settings['path'])) {
$settings['path'] = realpath($settings['path'] . DS . 'persistent') . DS;
if (!empty($coreCache['path'])) {
$coreCache['path'] = realpath($coreCache['path'] . DS . 'persistent') . DS;
$modelCache['path'] = realpath($modelCache['path'] . DS . 'models') . DS;
}
Cache::config('_cake_core_' , $settings);
Cache::config('_cake_core_' , $coreCache);
Cache::config('_cake_model_' , $modelCache);
}
$_this->buildPaths(compact('modelPaths', 'viewPaths', 'controllerPaths', 'helperPaths', 'componentPaths', 'behaviorPaths', 'pluginPaths', 'vendorPaths'));

View file

@ -205,17 +205,16 @@ class DataSource extends Object {
$expires = "+999 days";
}
if ($data != null) {
$data = serialize($data);
}
$filename = ConnectionManager::getSourceName($this) . '_' . preg_replace("/[^A-Za-z0-9_-]/", "_", $this->config['database']) . '_list';
$new = cache('models' . DS . $filename, $data, $expires);
$key = ConnectionManager::getSourceName($this) . '_' . Inflector::slug($this->config['database']) . '_list';
$sources = Cache::read($key, '_cake_model_');
if ($new != null) {
$new = unserialize($new);
$this->_sources = $new;
if ($sources == null) {
$sources = $data;
Cache::write($key, $data, array('duration' => $expires, 'config' => '_cake_model_'));
}
return $new;
$this->_sources = $sources;
return $sources;
}
/**
* Convenience method for DboSource::listSources(). Returns source names in lowercase.
@ -394,16 +393,17 @@ class DataSource extends Object {
if ($data !== null) {
$this->__descriptions[$object] =& $data;
$cache = serialize($data);
} else {
$cache = null;
}
$new = cache('models' . DS . ConnectionManager::getSourceName($this) . '_' . $object, $cache, $expires);
if ($new != null) {
$new = unserialize($new);
$key = ConnectionManager::getSourceName($this) . '_' . $object;
$cache = Cache::read($key, '_cake_model_');
if (empty($cache)) {
$cache = $data;
Cache::write($key, $cache, array('duration' => $expires, 'config' => '_cake_model_'));
}
return $new;
return $cache;
}
/**
* Enter description here...