Skip to content

Commit

Permalink
Fixes Bug 702350 - Add caching by default, and set up a way to clear …
Browse files Browse the repository at this point in the history
…the cache when we intentionally change the data.
  • Loading branch information
brandonsavage authored and rhelmer committed Nov 23, 2011
1 parent 44503a1 commit e17d6c3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions webapp-php/application/models/branch.php
Expand Up @@ -49,6 +49,22 @@
class Branch_Model extends Model {

protected static $_CACHE = array();
protected $_cache_obj;

public function __construct()
{
parent::__construct();
$this->_cache_obj = Cache::instance();
$c = $this->_cache_obj->get('branch.cache.objects');
if($c) {
self::$_CACHE = $c;
}
}

public function __destruct()
{
$this->_cache_obj->set('branch.cache.objects', self::$_CACHE, NULL, 1800);
}

protected function _getValues(array $order_by = array(), $ignore_cache = false) {
$order_by = implode(",", $order_by);
Expand Down Expand Up @@ -94,6 +110,11 @@ private function _sortVersions($versions)
return $versions_array;
}

protected function _clear_cache()
{
self::$_CACHE = array();
}

/**
* Add a new record to the branches view, via the productdims and product_visibility tables.
*
Expand All @@ -118,6 +139,7 @@ public function add($product, $version, $start_date, $end_date, $featured=false
} catch (Exception $e) {
Kohana::log('error', "Could not add \"$product\" \"$version\" in soc.web branch.add \r\n " . $e->getMessage());
}
$this->_clear_cache(); // We have changed the data, so we need to reload it.
return $rv;
}
}
Expand All @@ -140,6 +162,7 @@ public function delete($product, $version) {
AND version = ?
", $product, $version
);
$this->_clear_cache(); // We have changed the data, so we need to reload it.
return $rv;
}
}
Expand Down

0 comments on commit e17d6c3

Please sign in to comment.