Example #1
0
 /**
  * Common public method to create a cache instance given a definition.
  *
  * This is used by the static make methods.
  *
  * @param cache_definition $definition
  * @return cache_application|cache_session|cache_store
  * @throws coding_exception
  */
 public function create_cache(cache_definition $definition)
 {
     $class = $definition->get_cache_class();
     $stores = cache_helper::get_stores_suitable_for_definition($definition);
     foreach ($stores as $key => $store) {
         if (!$store::are_requirements_met()) {
             unset($stores[$key]);
         }
     }
     if (count($stores) === 0) {
         // Hmm still no stores, better provide a dummy store to mimic functionality. The dev will be none the wiser.
         $stores[] = $this->create_dummy_store($definition);
     }
     $loader = null;
     if ($definition->has_data_source()) {
         $loader = $definition->get_data_source();
     }
     while (($store = array_pop($stores)) !== null) {
         $loader = new $class($definition, $store, $loader);
     }
     return $loader;
 }
Example #2
0
 /**
  * Returns an array about the definitions. All the information a renderer needs.
  * @return array
  */
 public static function get_definition_summaries()
 {
     $factory = cache_factory::instance();
     $config = $factory->create_config_instance();
     $storenames = array();
     foreach ($config->get_all_stores() as $key => $store) {
         if (!empty($store['default'])) {
             $storenames[$key] = new lang_string('store_' . $key, 'cache');
         } else {
             $storenames[$store['name']] = $store['name'];
         }
     }
     /* @var cache_definition[] $definitions */
     $definitions = array();
     foreach ($config->get_definitions() as $key => $definition) {
         $definitions[$key] = cache_definition::load($definition['component'] . '/' . $definition['area'], $definition);
     }
     foreach ($definitions as $id => $definition) {
         $mappings = array();
         foreach (cache_helper::get_stores_suitable_for_definition($definition) as $store) {
             $mappings[] = $storenames[$store->my_name()];
         }
         $return[$id] = array('id' => $id, 'name' => $definition->get_name(), 'mode' => $definition->get_mode(), 'component' => $definition->get_component(), 'area' => $definition->get_area(), 'mappings' => $mappings, 'canuselocalstore' => $definition->can_use_localstore(), 'sharingoptions' => self::get_definition_sharing_options($definition->get_sharing_options(), false), 'selectedsharingoption' => self::get_definition_sharing_options($definition->get_selected_sharing_option(), true), 'userinputsharingkey' => $definition->get_user_input_sharing_key());
     }
     return $return;
 }