From 8b685a84dd938a86aac4bcc8e3e3a2292ff31351 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 28 May 2011 19:46:46 +1000 Subject: [PATCH] Enabled caching --- application/bootstrap.php | 3 +- application/classes/database/tsm.php | 13 ++++++- application/classes/model/node.php | 7 ++-- application/classes/ormtsm.php | 40 +++++++++++++++++++++- application/config/database.php | 20 ++++++++++- application/views/nodes/detail_volumes.php | 2 +- 6 files changed, 78 insertions(+), 7 deletions(-) diff --git a/application/bootstrap.php b/application/bootstrap.php index f93f414..280c1f1 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -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 )); /** diff --git a/application/classes/database/tsm.php b/application/classes/database/tsm.php index 39f6bb9..63f2c9d 100644 --- a/application/classes/database/tsm.php +++ b/application/classes/database/tsm.php @@ -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; } diff --git a/application/classes/model/node.php b/application/classes/model/node.php index d7f3dfc..a5a311b 100644 --- a/application/classes/model/node.php +++ b/application/classes/model/node.php @@ -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; } diff --git a/application/classes/ormtsm.php b/application/classes/ormtsm.php index b54b513..0e41f70 100644 --- a/application/classes/ormtsm.php +++ b/application/classes/ormtsm.php @@ -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); diff --git a/application/config/database.php b/application/config/database.php index 8ee3e50..bcefd6a 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -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, ), ); diff --git a/application/views/nodes/detail_volumes.php b/application/views/nodes/detail_volumes.php index 7b27ec1..ae82741 100644 --- a/application/views/nodes/detail_volumes.php +++ b/application/views/nodes/detail_volumes.php @@ -49,5 +49,5 @@   - +