Enabled caching

This commit is contained in:
Deon George 2011-05-28 19:46:46 +10:00
parent dcd6a54cb9
commit 8b685a84dd
6 changed files with 78 additions and 7 deletions

View File

@ -82,6 +82,7 @@ if (isset($_SERVER['KOHANA_ENV']))
Kohana::init(array(
'base_url' => '/pta',
'index_file' => '',
'caching' => TRUE,
));
/**
@ -105,7 +106,7 @@ Kohana::modules(array(
// 'image' => SMDPATH.'image', // Image manipulation
'orm' => SMDPATH.'orm', // Object Relationship Mapping
// 'unittest' => SMDPATH.'unittest', // Unit testing
// 'userguide' => SMDPATH.'userguide', // User guide and API documentation
'userguide' => SMDPATH.'userguide', // User guide and API documentation
));
/**

View File

@ -44,6 +44,17 @@ class Database_TSM extends Database {
public function rollback() {}
public function set_charset($charset) {}
/**
* Return the caching defined in the current configuration.
*
* $cache_time = $db->caching("table");
*
* @return string
*/
public function caching($table) {
return ($this->_config['caching'] AND isset($this->_config['cache'][$table])) ? $this->_config['cache'][$table] : FALSE;
}
public function connect() {
if ($this->_connection)
return;
@ -256,7 +267,7 @@ class Database_TSM extends Database {
}
// TSM attributes
$column['comment'] = $row['REMARKS'];
$column['comment'] = $row['REMARKS'];
$columns[$row['COLNAME']] = $column;
}

View File

@ -168,12 +168,15 @@ class Model_NODE extends ORMTSM {
// Return the volumes that this node uses
// $dtype is BACKUP or ARCHIVE
// @todo Cache this data
public function volumes($dtype) {
$volumes = array();
$v = array();
foreach ($this->VOLUMEUSAGE->where('COPY_TYPE','=',$dtype)->order_by('STGPOOL_NAME,FILESPACE_NAME')->find_all() as $vol)
$volumes[$vol->STGPOOL_NAME][] = $vol->VOLUME;
if (! in_array($vol->VOLUME->VOLUME_NAME,$v)) {
$volumes[$vol->STGPOOL_NAME][] = $vol->VOLUME;
array_push($v,$vol->VOLUME->VOLUME_NAME);
}
return $volumes;
}

View File

@ -17,12 +17,50 @@ class ORMTSM extends ORM {
protected $_disable_join_table_name = TRUE;
// Suppress ORMs use of limit
protected $_disable_limit = TRUE;
// To enable effective caching, this must disabled.
protected $_reload_on_wakeup = FALSE;
// Enable the formating of columns
protected $_object_formated = array();
protected $_object_formated = array();
protected $_formated = FALSE;
protected $_formats = array();
public function __construct($id = NULL) {
parent::__construct($id);
// We'll cache our query results
if ($c = $this->_db->caching($this->_table_name))
$this->cached($c);
}
/**
* Proxy method to Database list_columns.
* This enables caching of the list_columns queries. Since this doesnt
* we hard code the cache to 7 days.
*
* @return array
*/
public function list_columns() {
// We'll cache our query results
if ($this->_db->caching('SCHEMA')) {
// Set the cache key based on the database instance name and SQL
$cache_key = 'Database::query(LC:'.$this->_table_name.')';
if ($result = Cache::instance()->get($cache_key))
// Return a cached result
return $result;
}
// Proxy to database
$result = $this->_db->list_columns($this->_table_name);
// Cache the result array
if (isset($cache_key))
Cache::instance()->set($cache_key, $result, 604800);
return $result;
}
// Load our values into the ORM object
public function load_object(array $values) {
return parent::_load_values($values);

View File

@ -36,7 +36,25 @@ return array
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'caching' => TRUE,
'cache' => array(
'ASSOCIATIONS' => 1200,
'AR_COPYGROUPS' => 1200,
'BU_COPYGROUPS' => 1200,
'CLIENT_SCHEDULES' => 1200,
'CLIENTOPTS' => 1200,
'DEVCLASSES' => 1200,
'EVENTS' => 1200,
'FILESPACES' => 1200,
'MGMTCLASSES' => 1200,
'NODES' => 1200,
'OCCUPANCY' => 1200,
'SCHEMA' => 604800,
'STGPOOLS' => 1200,
'SUMMARY' => 60,
'VOLUMES' => 1200,
'VOLUMEUSAGE' => 1200,
),
'profiling' => TRUE,
),
);

View File

@ -49,5 +49,5 @@
 
</td>
</tr>
<? } ?>
<?php } ?>
</table>