Ejemplo n.º 1
0
 /**
  * Testing cachestore_file::get with prescan enabled and with
  * deleting the cache between the prescan and the call to get.
  *
  * The deleting of cache simulates some other process purging
  * the cache.
  */
 public function test_cache_get_with_prescan_and_purge()
 {
     global $CFG;
     $definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'cachestore_file', 'phpunit_test');
     $name = 'File test';
     $path = make_cache_directory('cachestore_file_test');
     $cache = new cachestore_file($name, array('path' => $path, 'prescan' => true));
     $cache->initialise($definition);
     $cache->set('testing', 'value');
     $path = make_cache_directory('cachestore_file_test');
     $cache = new cachestore_file($name, array('path' => $path, 'prescan' => true));
     $cache->initialise($definition);
     // Let's pretend that some other process purged caches.
     remove_dir($CFG->cachedir . '/cachestore_file_test', true);
     make_cache_directory('cachestore_file_test');
     $cache->get('testing');
 }
 /**
  * Returns an array of default stores for use.
  *
  * @return array
  */
 protected static function get_default_stores()
 {
     global $CFG;
     require_once $CFG->dirroot . '/cache/stores/file/lib.php';
     require_once $CFG->dirroot . '/cache/stores/session/lib.php';
     require_once $CFG->dirroot . '/cache/stores/static/lib.php';
     return array('default_application' => array('name' => 'default_application', 'plugin' => 'file', 'configuration' => array(), 'features' => cachestore_file::get_supported_features(), 'modes' => cachestore_file::get_supported_modes(), 'default' => true), 'default_session' => array('name' => 'default_session', 'plugin' => 'session', 'configuration' => array(), 'features' => cachestore_session::get_supported_features(), 'modes' => cachestore_session::get_supported_modes(), 'default' => true), 'default_request' => array('name' => 'default_request', 'plugin' => 'static', 'configuration' => array(), 'features' => cachestore_static::get_supported_features(), 'modes' => cachestore_static::get_supported_modes(), 'default' => true));
 }
Ejemplo n.º 3
0
 /**
  * Generates an instance of the cache store that can be used for testing.
  *
  * Returns an instance of the cache store, or false if one cannot be created.
  *
  * @param cache_definition $definition
  * @return cachestore_file
  */
 public static function initialise_test_instance(cache_definition $definition)
 {
     $name = 'File test';
     $path = make_cache_directory('cachestore_file_test');
     $cache = new cachestore_file($name, array('path' => $path));
     $cache->initialise($definition);
     return $cache;
 }
Ejemplo n.º 4
0
 /**
  * Creates the default configuration and saves it.
  *
  * This function calls config_save, however it is safe to continue using it afterwards as this function should only ever
  * be called when there is no configuration file already.
  *
  * @return true|array Returns true if the default configuration was successfully created.
  *     Returns a configuration array if it could not be saved. This is a bad situation. Check your error logs.
  */
 public static function create_default_configuration()
 {
     global $CFG;
     // HACK ALERT.
     // We probably need to come up with a better way to create the default stores, or at least ensure 100% that the
     // default store plugins are protected from deletion.
     require_once $CFG->dirroot . '/cache/stores/file/lib.php';
     require_once $CFG->dirroot . '/cache/stores/session/lib.php';
     require_once $CFG->dirroot . '/cache/stores/static/lib.php';
     $writer = new self();
     $writer->configstores = array('default_application' => array('name' => 'default_application', 'plugin' => 'file', 'configuration' => array(), 'features' => cachestore_file::get_supported_features(), 'modes' => cache_store::MODE_APPLICATION, 'default' => true), 'default_session' => array('name' => 'default_session', 'plugin' => 'session', 'configuration' => array(), 'features' => cachestore_session::get_supported_features(), 'modes' => cache_store::MODE_SESSION, 'default' => true), 'default_request' => array('name' => 'default_request', 'plugin' => 'static', 'configuration' => array(), 'features' => cachestore_static::get_supported_features(), 'modes' => cache_store::MODE_REQUEST, 'default' => true));
     $writer->configdefinitions = self::locate_definitions();
     $writer->configmodemappings = array(array('mode' => cache_store::MODE_APPLICATION, 'store' => 'default_application', 'sort' => -1), array('mode' => cache_store::MODE_SESSION, 'store' => 'default_session', 'sort' => -1), array('mode' => cache_store::MODE_REQUEST, 'store' => 'default_request', 'sort' => -1));
     $writer->configlocks = array('default_file_lock' => array('name' => 'cachelock_file_default', 'type' => 'cachelock_file', 'dir' => 'filelocks', 'default' => true));
     $factory = cache_factory::instance();
     // We expect the cache to be initialising presently. If its not then something has gone wrong and likely
     // we are now in a loop.
     if ($factory->get_state() !== cache_factory::STATE_INITIALISING) {
         return $writer->generate_configuration_array();
     }
     $factory->set_state(cache_factory::STATE_SAVING);
     $writer->config_save();
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Creates the default configuration and saves it.
  *
  * @param bool $forcesave Ignored because we are disabled!
  * @return array
  */
 public static function create_default_configuration($forcesave = false)
 {
     global $CFG;
     // HACK ALERT.
     // We probably need to come up with a better way to create the default stores, or at least ensure 100% that the
     // default store plugins are protected from deletion.
     require_once $CFG->dirroot . '/cache/stores/file/lib.php';
     require_once $CFG->dirroot . '/cache/stores/session/lib.php';
     require_once $CFG->dirroot . '/cache/stores/static/lib.php';
     $writer = new self();
     $writer->configstores = array('default_application' => array('name' => 'default_application', 'plugin' => 'file', 'configuration' => array(), 'features' => cachestore_file::get_supported_features(), 'modes' => cache_store::MODE_APPLICATION, 'default' => true), 'default_session' => array('name' => 'default_session', 'plugin' => 'session', 'configuration' => array(), 'features' => cachestore_session::get_supported_features(), 'modes' => cache_store::MODE_SESSION, 'default' => true), 'default_request' => array('name' => 'default_request', 'plugin' => 'static', 'configuration' => array(), 'features' => cachestore_static::get_supported_features(), 'modes' => cache_store::MODE_REQUEST, 'default' => true));
     $writer->configdefinitions = array();
     $writer->configmodemappings = array(array('mode' => cache_store::MODE_APPLICATION, 'store' => 'default_application', 'sort' => -1), array('mode' => cache_store::MODE_SESSION, 'store' => 'default_session', 'sort' => -1), array('mode' => cache_store::MODE_REQUEST, 'store' => 'default_request', 'sort' => -1));
     $writer->configlocks = array('default_file_lock' => array('name' => 'cachelock_file_default', 'type' => 'cachelock_file', 'dir' => 'filelocks', 'default' => true));
     return $writer->generate_configuration_array();
 }