** Data guarantee - Data is guaranteed to exist in the cache once it is set there. It is never cleaned up to free space or because it has not been recently used.
** Multiple identifiers - Rather than a single string key, the parts that make up the key are passed as an array.
** Native TTL support - When required, the store supports native ttl and doesn't require the cache API to manage ttl of things given to the store.
+* There are two reserved store names, base and dummy. These are both used internally.
### Definition
_Definitions were not a part of the previous proposal._
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Cache store - base class
+ *
+ * This file is part of Moodle's cache API, affectionately called MUC.
+ * It contains the components that are required in order to use caching.
+ *
+ * @package core
+ * @category cache
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Abstract cache store base class.
+ *
+ * This class implements the cache_store interface that all caches store plugins are required in implement.
+ * It then implements basic methods that likely won't need to be overridden by plugins.
+ * It will also be used to implement any API changes that come about in the future.
+ *
+ * While it is not required that you extend this class it is highly recommended.
+ *
+ * @since 2.4
+ * @package core
+ * @category cache
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+abstract class cache_store_base implements cache_store {
+
+ /**
+ * Returns true if the user can add an instance of the store plugin.
+ *
+ * @return bool
+ */
+ public static function can_add_instance() {
+ return true;
+ }
+
+ /**
+ * Returns true if the store instance guarantees data.
+ *
+ * @return bool
+ */
+ public function supports_data_guarantee() {
+ return $this::get_supported_features() & self::SUPPORTS_DATA_GUARANTEE;
+ }
+
+ /**
+ * Returns true if the store instance supports multiple identifiers.
+ *
+ * @return bool
+ */
+ public function supports_multiple_identifiers() {
+ return $this::get_supported_features() & self::SUPPORTS_MULTIPLE_IDENTIFIERS;
+ }
+
+ /**
+ * Returns true if the store instance supports native ttl.
+ *
+ * @return bool
+ */
+ public function supports_native_ttl() {
+ return $this::supports_data_guarantee() & self::SUPPORTS_NATIVE_TTL;
+ }
+}
\ No newline at end of file
require_once($CFG->dirroot.'/cache/classes/helper.php');
require_once($CFG->dirroot.'/cache/classes/factory.php');
require_once($CFG->dirroot.'/cache/classes/loaders.php');
+require_once($CFG->dirroot.'/cache/classes/store.php');
require_once($CFG->dirroot.'/cache/classes/definition.php');
/**
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class cachestore_file implements cache_store, cache_is_key_aware {
+class cachestore_file extends cache_store_base implements cache_is_key_aware {
/**
* The name of the store.
return ($mode === self::MODE_APPLICATION || $mode === self::MODE_SESSION);
}
- /**
- * Returns true if the store instance supports multiple identifiers.
- *
- * @return bool
- */
- public function supports_multiple_identifiers() {
- return false;
- }
-
- /**
- * Returns true if the store instance guarantees data.
- *
- * @return bool
- */
- public function supports_data_guarantee() {
- return true;
- }
-
- /**
- * Returns true if the store instance supports native ttl.
- *
- * @return bool
- */
- public function supports_native_ttl() {
- return true;
- }
-
/**
* Initialises the cache.
*
return true;
}
- /**
- * Returns true if the user can add an instance of the store plugin.
- *
- * @return bool
- */
- public static function can_add_instance() {
- return true;
- }
-
/**
* Performs any necessary clean up when the store instance is being deleted.
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class cachestore_memcache implements cache_store {
+class cachestore_memcache extends cache_store_base {
/**
* The name of the store
return self::SUPPORTS_NATIVE_TTL;
}
- /**
- * Returns true if the store instance supports multiple identifiers.
- *
- * @return bool
- */
- public function supports_multiple_identifiers() {
- return false;
- }
-
- /**
- * Returns true if the store instance guarantees data.
- *
- * @return bool
- */
- public function supports_data_guarantee() {
- return false;
- }
-
- /**
- * Returns true if the store instance supports native ttl.
- *
- * @return bool
- */
- public function supports_native_ttl() {
- return true;
- }
-
/**
* Returns the supported modes as a combined int.
*
$editform->set_data($data);
}
- /**
- * Returns true if the user can add an instance of the store plugin.
- *
- * @return bool
- */
- public static function can_add_instance() {
- return true;
- }
-
/**
* Performs any necessary clean up when the store instance is being deleted.
*/
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class cachestore_memcached implements cache_store {
+class cachestore_memcached extends cache_store_base {
/**
* The name of the store
return self::SUPPORTS_NATIVE_TTL;
}
- /**
- * Returns true if the store instance supports multiple identifiers.
- *
- * @return bool
- */
- public function supports_multiple_identifiers() {
- return false;
- }
-
- /**
- * Returns true if the store instance guarantees data.
- *
- * @return bool
- */
- public function supports_data_guarantee() {
- return false;
- }
-
- /**
- * Returns true if the store instance supports native ttl.
- *
- * @return bool
- */
- public function supports_native_ttl() {
- return true;
- }
-
/**
* Returns the supported modes as a combined int.
*
$editform->set_data($data);
}
- /**
- * Returns true if the user can add an instance of the store plugin.
- *
- * @return bool
- */
- public static function can_add_instance() {
- return true;
- }
-
/**
* Performs any necessary clean up when the store instance is being deleted.
*/
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class cachestore_mongodb implements cache_store {
+class cachestore_mongodb extends cache_store_base {
/**
* The name of the store
return class_exists('Mongo');
}
- /**
- * Returns true if the user can add an instance of this store.
- * @return bool
- */
- public static function can_add_instance() {
- return true;
- }
-
/**
* Returns the supported features.
* @param array $configuration
return ($mode == self::MODE_APPLICATION || $mode == self::MODE_SESSION);
}
- /**
- * Returns true if this store guarantees its data is there once set.
- * @return bool
- */
- public function supports_data_guarantee() {
- return true;
- }
-
/**
* Returns true if this store is making use of multiple identifiers.
* @return bool
return $this->extendedmode;
}
- /**
- * Returns true if this store supports native TTL.
- * @return bool
- */
- public function supports_native_ttl() {
- return false;
- }
-
/**
* Retrieves an item from the cache store given its key.
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class cachestore_session extends session_data_store implements cache_store, cache_is_key_aware {
+class cachestore_session extends session_data_store implements cache_is_key_aware {
/**
* The name of the store
return ($mode === self::MODE_SESSION);
}
- /**
- * Returns true if the store instance guarantees data.
- *
- * @return bool
- */
- public function supports_data_guarantee() {
- return true;
- }
-
- /**
- * Returns true if the store instance supports multiple identifiers.
- *
- * @return bool
- */
- public function supports_multiple_identifiers() {
- return false;
- }
-
- /**
- * Returns true if the store instance supports native ttl.
- *
- * @return bool
- */
- public function supports_native_ttl() {
- return true;
- }
-
/**
* Initialises the cache.
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-abstract class session_data_store {
+abstract class session_data_store extends cache_store_base {
/**
* Used for the actual storage.
return ($mode === self::MODE_REQUEST);
}
- /**
- * Returns true if the store instance guarantees data.
- *
- * @return bool
- */
- public function supports_data_guarantee() {
- return true;
- }
-
- /**
- * Returns true if the store instance supports multiple identifiers.
- *
- * @return bool
- */
- public function supports_multiple_identifiers() {
- return false;
- }
-
- /**
- * Returns true if the store instance supports native ttl.
- *
- * @return bool
- */
- public function supports_native_ttl() {
- return true;
- }
-
/**
* Initialises the cache.
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-abstract class static_data_store {
+abstract class static_data_store extends cache_store_base {
/**
* An array for storage.