Skip to content

Commit

Permalink
MDL-36768 cache: Fixed regression in cache stores by reordering classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Nov 26, 2012
1 parent 0aa6247 commit b144e12
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 109 deletions.
112 changes: 56 additions & 56 deletions cache/stores/session/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,62 @@

defined('MOODLE_INTERNAL') || die();

/**
* The session data store class.
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class session_data_store extends cache_store {

/**
* Used for the actual storage.
* @var array
*/
private static $sessionstore = null;

/**
* Returns a static store by reference... REFERENCE SUPER IMPORTANT.
*
* @param string $id
* @return array
*/
protected static function &register_store_id($id) {
if (is_null(self::$sessionstore)) {
global $SESSION;
if (!isset($SESSION->cachestore_session)) {
$SESSION->cachestore_session = array();
}
self::$sessionstore =& $SESSION->cachestore_session;
}
if (!array_key_exists($id, self::$sessionstore)) {
self::$sessionstore[$id] = array();
}
return self::$sessionstore[$id];
}

/**
* Flushes the data belong to the given store id.
* @param string $id
*/
protected static function flush_store_by_id($id) {
unset(self::$sessionstore[$id]);
self::$sessionstore[$id] = array();
}

/**
* Flushes the store of all data.
*/
protected static function flush_store() {
$ids = array_keys(self::$sessionstore);
unset(self::$sessionstore);
self::$sessionstore = array();
foreach ($ids as $id) {
self::$sessionstore[$id] = array();
}
}
}

/**
* The Session store class.
*
Expand Down Expand Up @@ -343,60 +399,4 @@ public static function initialise_test_instance(cache_definition $definition) {
public function my_name() {
return $this->name;
}
}

/**
* The session data store class.
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class session_data_store extends cache_store {

/**
* Used for the actual storage.
* @var array
*/
private static $sessionstore = null;

/**
* Returns a static store by reference... REFERENCE SUPER IMPORTANT.
*
* @param string $id
* @return array
*/
protected static function &register_store_id($id) {
if (is_null(self::$sessionstore)) {
global $SESSION;
if (!isset($SESSION->cachestore_session)) {
$SESSION->cachestore_session = array();
}
self::$sessionstore =& $SESSION->cachestore_session;
}
if (!array_key_exists($id, self::$sessionstore)) {
self::$sessionstore[$id] = array();
}
return self::$sessionstore[$id];
}

/**
* Flushes the data belong to the given store id.
* @param string $id
*/
protected static function flush_store_by_id($id) {
unset(self::$sessionstore[$id]);
self::$sessionstore[$id] = array();
}

/**
* Flushes the store of all data.
*/
protected static function flush_store() {
$ids = array_keys(self::$sessionstore);
unset(self::$sessionstore);
self::$sessionstore = array();
foreach ($ids as $id) {
self::$sessionstore[$id] = array();
}
}
}
106 changes: 53 additions & 53 deletions cache/stores/static/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,58 @@

defined('MOODLE_INTERNAL') || die();

/**
* The static data store class
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class static_data_store extends cache_store {

/**
* An array for storage.
* @var array
*/
private static $staticstore = array();

/**
* Returns a static store by reference... REFERENCE SUPER IMPORTANT.
*
* @param string $id
* @return array
*/
protected static function &register_store_id($id) {
if (!array_key_exists($id, self::$staticstore)) {
self::$staticstore[$id] = array();
}
return self::$staticstore[$id];
}

/**
* Flushes the store of all values for belonging to the store with the given id.
* @param string $id
*/
protected static function flush_store_by_id($id) {
unset(self::$staticstore[$id]);
self::$staticstore[$id] = array();
}

/**
* Flushes all of the values from all stores.
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
protected static function flush_store() {
$ids = array_keys(self::$staticstore);
unset(self::$staticstore);
self::$staticstore = array();
foreach ($ids as $id) {
self::$staticstore[$id] = array();
}
}
}

/**
* The static store class.
*
Expand Down Expand Up @@ -343,56 +395,4 @@ public static function initialise_test_instance(cache_definition $definition) {
public function my_name() {
return $this->name;
}
}

/**
* The static data store class
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class static_data_store extends cache_store {

/**
* An array for storage.
* @var array
*/
private static $staticstore = array();

/**
* Returns a static store by reference... REFERENCE SUPER IMPORTANT.
*
* @param string $id
* @return array
*/
protected static function &register_store_id($id) {
if (!array_key_exists($id, self::$staticstore)) {
self::$staticstore[$id] = array();
}
return self::$staticstore[$id];
}

/**
* Flushes the store of all values for belonging to the store with the given id.
* @param string $id
*/
protected static function flush_store_by_id($id) {
unset(self::$staticstore[$id]);
self::$staticstore[$id] = array();
}

/**
* Flushes all of the values from all stores.
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
protected static function flush_store() {
$ids = array_keys(self::$staticstore);
unset(self::$staticstore);
self::$staticstore = array();
foreach ($ids as $id) {
self::$staticstore[$id] = array();
}
}
}
}

0 comments on commit b144e12

Please sign in to comment.