当前位置: 首页>>代码示例>>PHP>>正文


PHP cache_factory类代码示例

本文整理汇总了PHP中cache_factory的典型用法代码示例。如果您正苦于以下问题:PHP cache_factory类的具体用法?PHP cache_factory怎么用?PHP cache_factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了cache_factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: configuration_validation

 /**
  * Validates the configuration data.
  *
  * We need to check that prefix is unique.
  *
  * @param array $data
  * @param array $files
  * @param array $errors
  * @return array
  * @throws coding_exception
  */
 public function configuration_validation($data, $files, array $errors)
 {
     if (empty($errors['prefix'])) {
         $factory = cache_factory::instance();
         $config = $factory->create_config_instance();
         foreach ($config->get_all_stores() as $store) {
             if ($store['plugin'] === 'apcu') {
                 if (isset($store['configuration']['prefix'])) {
                     if ($data['prefix'] === $store['configuration']['prefix']) {
                         // The new store has the same prefix as an existing store, thats a problem.
                         $errors['prefix'] = get_string('prefixnotunique', 'cachestore_apcu');
                         break;
                     }
                 } else {
                     if (empty($data['prefix'])) {
                         // The existing store hasn't got a prefix and neither does the new store, that's a problem.
                         $errors['prefix'] = get_string('prefixnotunique', 'cachestore_apcu');
                         break;
                     }
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:janeklb,项目名称:moodle,代码行数:36,代码来源:addinstanceform.php

示例2: configuration_validation

 /**
  * Performs custom validation for us.
  *
  * @param array $data An array of data sent to the form.
  * @param array $files An array of files sent to the form.
  * @return array An array of errors.
  */
 protected function configuration_validation($data, $files)
 {
     $errors = array();
     if (!array_key_exists('prefix', $data)) {
         $prefix = '';
     } else {
         $prefix = clean_param($data['prefix'], PARAM_ALPHANUM);
     }
     $factory = cache_factory::instance();
     $config = $factory->create_config_instance();
     foreach ($config->get_all_stores() as $store) {
         if ($store['plugin'] !== 'xcache') {
             continue;
         }
         if (empty($store['configuration']['prefix'])) {
             $storeprefix = '';
         } else {
             $storeprefix = $store['configuration']['prefix'];
         }
         if ($storeprefix === $prefix) {
             $errors['prefix'] = get_string('erroruniqueprefix');
         }
     }
     return $errors;
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:32,代码来源:addinstanceform.php

示例3: instance

 /**
  * Returns an instance of the cache_factor method.
  *
  * @param bool $forcereload If set to true a new cache_factory instance will be created and used.
  * @return cache_factory
  */
 public static function instance($forcereload = false)
 {
     if ($forcereload || self::$instance === null) {
         self::$instance = new cache_factory();
     }
     return self::$instance;
 }
开发者ID:numbas,项目名称:moodle,代码行数:13,代码来源:factory.php

示例4: get_instance

 /**
  * 返回当前终级类对象的实例
  * @param $cache_config 缓存配置
  * @return object
  */
 public static function get_instance($cache_config = '')
 {
     if (cache_factory::$cache_factory == '') {
         cache_factory::$cache_factory = new cache_factory();
         if (!empty($cache_config)) {
             cache_factory::$cache_factory->cache_config = $cache_config;
         }
     }
     return cache_factory::$cache_factory;
 }
开发者ID:boylzj,项目名称:omguitar,代码行数:15,代码来源:cache_factory.class.php

示例5: get_instance

 /**
  * 返回当前缓存工厂类实例
  * @param array $cache_config
  */
 public static function get_instance($cache_config = array())
 {
     //当前工厂类实例为空时初始化该对象
     if (cache_factory::$cache_factory == '' || !empty($cache_config)) {
         cache_factory::$cache_factory = new cache_factory();
         if (!empty($cache_config)) {
             cache_factory::$cache_factory->cache_config = $cache_config;
         }
     }
     return cache_factory::$cache_factory;
 }
开发者ID:h3len,项目名称:Project,代码行数:15,代码来源:cache.class.php

示例6: get_instance

 /**
  * 返回当前终级类对象的实例
  * @param $cache_config 缓存配置
  * @return object
  */
 public static function get_instance($cache_config = '')
 {
     if (!$cache_config) {
         $cache_config = array('type' => 'zendfile');
     }
     if (cache_factory::$cache_factory == '') {
         cache_factory::$cache_factory = new cache_factory();
         if (!empty($cache_config)) {
             cache_factory::$cache_factory->cache_config = $cache_config;
         }
     }
     return cache_factory::$cache_factory;
 }
开发者ID:ailingsen,项目名称:pigcms,代码行数:18,代码来源:cache_factory.class.php

示例7: phpunit_disable

 /**
  * Exposes the cache_factory's disable method.
  *
  * Perhaps one day that method will be made public, for the time being it is protected.
  */
 public static function phpunit_disable()
 {
     parent::disable();
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:9,代码来源:lib.php

示例8: get_stores_suitable_for_definition

 /**
  * Returns stores suitable for use with a given definition.
  *
  * @param cache_definition $definition
  * @return cache_store[]
  */
 public static function get_stores_suitable_for_definition(cache_definition $definition)
 {
     $factory = cache_factory::instance();
     $stores = array();
     if ($factory->is_initialising() || $factory->stores_disabled()) {
         // No suitable stores here.
         return $stores;
     } else {
         $stores = self::get_cache_stores($definition);
         // If mappingsonly is set, having 0 stores is ok.
         if (count($stores) === 0 && !$definition->is_for_mappings_only()) {
             // No suitable stores we found for the definition. We need to come up with a sensible default.
             // If this has happened we can be sure that the user has mapped custom stores to either the
             // mode of the definition. The first alternative to try is the system default for the mode.
             // e.g. the default file store instance for application definitions.
             $config = $factory->create_config_instance();
             foreach ($config->get_stores($definition->get_mode()) as $name => $details) {
                 if (!empty($details['default'])) {
                     $stores[] = $factory->create_store_from_config($name, $details, $definition);
                     break;
                 }
             }
         }
     }
     return $stores;
 }
开发者ID:Keneth1212,项目名称:moodle,代码行数:32,代码来源:helper.php

示例9: reset_dataroot

 /**
  * Purge dataroot directory
  * @static
  * @return void
  */
 public static function reset_dataroot()
 {
     global $CFG;
     $childclassname = self::get_framework() . '_util';
     // Do not delete automatically installed files.
     self::skip_original_data_files($childclassname);
     // Clear file status cache, before checking file_exists.
     clearstatcache();
     // Clean up the dataroot folder.
     $handle = opendir(self::get_dataroot());
     while (false !== ($item = readdir($handle))) {
         if (in_array($item, $childclassname::$datarootskiponreset)) {
             continue;
         }
         if (is_dir(self::get_dataroot() . "/{$item}")) {
             remove_dir(self::get_dataroot() . "/{$item}", false);
         } else {
             unlink(self::get_dataroot() . "/{$item}");
         }
     }
     closedir($handle);
     // Clean up the dataroot/filedir folder.
     if (file_exists(self::get_dataroot() . '/filedir')) {
         $handle = opendir(self::get_dataroot() . '/filedir');
         while (false !== ($item = readdir($handle))) {
             if (in_array('filedir/' . $item, $childclassname::$datarootskiponreset)) {
                 continue;
             }
             if (is_dir(self::get_dataroot() . "/filedir/{$item}")) {
                 remove_dir(self::get_dataroot() . "/filedir/{$item}", false);
             } else {
                 unlink(self::get_dataroot() . "/filedir/{$item}");
             }
         }
         closedir($handle);
     }
     make_temp_directory('');
     make_cache_directory('');
     make_localcache_directory('');
     // Reset the cache API so that it recreates it's required directories as well.
     cache_factory::reset();
     // Purge all data from the caches. This is required for consistency.
     // Any file caches that happened to be within the data root will have already been clearer (because we just deleted cache)
     // and now we will purge any other caches as well.
     cache_helper::purge_all();
 }
开发者ID:matiasma,项目名称:moodle,代码行数:51,代码来源:util.php

示例10: clean_old_session_data

 /**
  * Cleans old session data from cache stores used for session based definitions.
  *
  * @param bool $output If set to true output will be given.
  */
 public static function clean_old_session_data($output = false)
 {
     global $CFG;
     if ($output) {
         mtrace('Cleaning up stale session data from cache stores.');
     }
     $factory = cache_factory::instance();
     $config = $factory->create_config_instance();
     $definitions = $config->get_definitions();
     $purgetime = time() - $CFG->sessiontimeout;
     foreach ($definitions as $definitionarray) {
         // We are only interested in session caches.
         if (!($definitionarray['mode'] & cache_store::MODE_SESSION)) {
             continue;
         }
         $definition = $factory->create_definition($definitionarray['component'], $definitionarray['area']);
         $stores = $config->get_stores_for_definition($definition);
         // Turn them into store instances.
         $stores = self::initialise_cachestore_instances($stores, $definition);
         // Initialise all of the stores used for that definition.
         foreach ($stores as $store) {
             // If the store doesn't support searching we can skip it.
             if (!$store instanceof cache_is_searchable) {
                 debugging('Cache stores used for session definitions should ideally be searchable.', DEBUG_DEVELOPER);
                 continue;
             }
             // Get all of the keys.
             $keys = $store->find_by_prefix(cache_session::KEY_PREFIX);
             $todelete = array();
             foreach ($store->get_many($keys) as $key => $value) {
                 if (strpos($key, cache_session::KEY_PREFIX) !== 0 || !is_array($value) || !isset($value['lastaccess'])) {
                     continue;
                 }
                 if ((int) $value['lastaccess'] < $purgetime || true) {
                     $todelete[] = $key;
                 }
             }
             if (count($todelete)) {
                 $outcome = (int) $store->delete_many($todelete);
                 if ($output) {
                     $strdef = s($definition->get_id());
                     $strstore = s($store->my_name());
                     mtrace("- Removed {$outcome} old {$strdef} sessions from the '{$strstore}' cache store.");
                 }
             }
         }
     }
 }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:53,代码来源:helper.php

示例11: required_param

 case 'purgestore':
 case 'purge':
     // Purge a store cache.
     $store = required_param('store', PARAM_TEXT);
     cache_helper::purge_store($store);
     redirect($PAGE->url, get_string('purgestoresuccess', 'cache'), 5);
     break;
 case 'newlockinstance':
     // Adds a new lock instance.
     $lock = required_param('lock', PARAM_ALPHANUMEXT);
     $mform = cache_administration_helper::get_add_lock_form($lock);
     if ($mform->is_cancelled()) {
         redirect($PAGE->url);
     } else {
         if ($data = $mform->get_data()) {
             $factory = cache_factory::instance();
             $config = $factory->create_config_instance(true);
             $name = $data->name;
             $data = cache_administration_helper::get_lock_configuration_from_data($lock, $data);
             $config->add_lock_instance($name, $lock, $data);
             redirect($PAGE->url, get_string('addlocksuccess', 'cache', $name), 5);
         }
     }
     break;
 case 'deletelock':
     // Deletes a lock instance.
     $lock = required_param('lock', PARAM_ALPHANUMEXT);
     $confirm = optional_param('confirm', false, PARAM_BOOL);
     if (!array_key_exists($lock, $locks)) {
         $notifysuccess = false;
         $notification = get_string('invalidlock', 'cache');
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:31,代码来源:admin.php

示例12: disable

 /**
  * Disables as much of the cache API as possible.
  *
  * All of the magic associated with the disabled cache is wrapped into this function.
  * In switching out the factory for the disabled factory it gains full control over the initialisation of objects
  * and can use all of the disabled alternatives.
  * Simple!
  *
  * This function has been marked as protected so that it cannot be abused through the public API presently.
  * Perhaps in the future we will allow this, however as per the build up to the first release containing
  * MUC it was decided that this was just to risky and abusable.
  */
 protected static function disable()
 {
     global $CFG;
     require_once $CFG->dirroot . '/cache/disabledlib.php';
     self::$instance = new cache_factory_disabled();
 }
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:18,代码来源:factory.php

示例13: update_definitions

 /**
  * Finds all definitions and updates them within the cache config file.
  *
  * @param bool $coreonly If set to true only core definitions will be updated.
  */
 public static function update_definitions($coreonly = false)
 {
     global $CFG;
     // Include locallib
     require_once $CFG->dirroot . '/cache/locallib.php';
     // First update definitions
     cache_config_writer::update_definitions($coreonly);
     // Second reset anything we have already initialised to ensure we're all up to date.
     cache_factory::reset();
 }
开发者ID:numbas,项目名称:moodle,代码行数:15,代码来源:helper.php

示例14: getcacheinfo

/**
 * 读取缓存,默认为文件缓存,不加载缓存配置。
 * @param string $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param string $config 配置名称
 */
function getcacheinfo($name, $filepath = '', $type = 'file', $config = '')
{
    pc_base::load_sys_class('cache_factory');
    if ($config) {
        $cacheconfig = pc_base::load_config('cache');
        $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
    } else {
        $cache = cache_factory::get_instance()->get_cache($type);
    }
    return $cache->cacheinfo($name, '', '', $filepath);
}
开发者ID:hw18708118867,项目名称:htmlmoban,代码行数:17,代码来源:global.func.php

示例15: test_disable

 /**
  * Test disabling the cache.
  */
 public function test_disable()
 {
     global $CFG;
     $configfile = $CFG->dataroot . '/muc/config.php';
     // That's right, we're deleting the config file.
     $this->assertTrue(@unlink($configfile));
     // Disable the cache
     cache_phpunit_factory::phpunit_disable();
     // Check we get the expected disabled factory.
     $factory = cache_factory::instance();
     $this->assertInstanceOf('cache_factory_disabled', $factory);
     // Check we get the expected disabled config.
     $config = $factory->create_config_instance();
     $this->assertInstanceOf('cache_config_disabled', $config);
     // Check we get the expected disabled caches.
     $cache = cache::make('phpunit', 'disable');
     $this->assertInstanceOf('cache_disabled', $cache);
     $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'phpunit', 'disable');
     $this->assertInstanceOf('cache_disabled', $cache);
     $this->assertFalse(file_exists($configfile));
     $this->assertFalse($cache->get('test'));
     $this->assertFalse($cache->set('test', 'test'));
     $this->assertFalse($cache->delete('test'));
     $this->assertTrue($cache->purge());
     cache_factory::reset();
     $factory = cache_factory::instance(true);
     $config = $factory->create_config_instance();
     $this->assertEquals('cache_config_phpunittest', get_class($config));
 }
开发者ID:Burick,项目名称:moodle,代码行数:32,代码来源:cache_test.php


注:本文中的cache_factory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。