本文整理汇总了PHP中cache::make_from_params方法的典型用法代码示例。如果您正苦于以下问题:PHP cache::make_from_params方法的具体用法?PHP cache::make_from_params怎么用?PHP cache::make_from_params使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache
的用法示例。
在下文中一共展示了cache::make_from_params方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter_matches
/**
* Check whether the filter matches the specified tour and/or context.
*
* @param tour $tour The tour to check
* @param context $context The context to check
* @return boolean
*/
public static function filter_matches(tour $tour, context $context)
{
global $USER;
$values = $tour->get_filter_values(self::get_filter_name());
if (empty($values)) {
// There are no values configured.
// No values means all.
return true;
}
if (is_siteadmin()) {
return true;
}
// Presence within the array is sufficient. Ignore any value.
$values = array_flip($values);
$cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'tool_usertours', 'filter_role');
$cachekey = "{$USER->id}_{$context->id}";
$userroles = $cache->get($cachekey);
if ($userroles === false) {
$userroles = get_user_roles_with_special($context);
$cache->set($cachekey, $userroles);
}
foreach ($userroles as $role) {
if (isset($values[$role->roleid])) {
return true;
}
}
return false;
}
示例2: __construct
/**
* Create new instance of string manager
*
* @param string $otherroot location of downloaded lang packs - usually $CFG->dataroot/lang
* @param string $localroot usually the same as $otherroot
* @param array $translist limit list of visible translations
*/
public function __construct($otherroot, $localroot, $translist)
{
$this->otherroot = $otherroot;
$this->localroot = $localroot;
if ($translist) {
$this->translist = array_combine($translist, $translist);
} else {
$this->translist = array();
}
if ($this->get_revision() > 0) {
// We can use a proper cache, establish the cache using the 'String cache' definition.
$this->cache = cache::make('core', 'string');
$this->menucache = cache::make('core', 'langmenu');
} else {
// We only want a cache for the length of the request, create a static cache.
$options = array('simplekeys' => true, 'simpledata' => true);
$this->cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core', 'string', array(), $options);
$this->menucache = cache::make_from_params(cache_store::MODE_REQUEST, 'core', 'langmenu', array(), $options);
}
}
示例3: password_compat_not_supported
/**
* Checks whether the password compatibility library will work with the current
* version of PHP. This cannot be done using PHP version numbers since the fix
* has been backported to earlier versions in some distributions.
*
* See https://github.com/ircmaxell/password_compat/issues/10 for more details.
*
* @return bool True if the library is NOT supported.
*/
function password_compat_not_supported()
{
$hash = '$2y$04$usesomesillystringfore7hnbRJHxXVLeakoG8K30oukPsA.ztMG';
// Create a one off application cache to store bcrypt support status as
// the support status doesn't change and crypt() is slow.
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'core', 'password_compat');
if (!($bcryptsupport = $cache->get('bcryptsupport'))) {
$test = crypt('password', $hash);
// Cache string instead of boolean to avoid MDL-37472.
if ($test == $hash) {
$bcryptsupport = 'supported';
} else {
$bcryptsupport = 'not supported';
}
$cache->set('bcryptsupport', $bcryptsupport);
}
// Return true if bcrypt *not* supported.
return $bcryptsupport !== 'supported';
}
示例4: process_save_grade
/**
* Save grade.
*
* @param moodleform $mform
* @return bool - was the grade saved
*/
protected function process_save_grade(&$mform) {
global $CFG;
// Include grade form.
require_once($CFG->dirroot . '/mod/assign/gradeform.php');
// Need submit permission to submit an assignment.
require_capability('mod/assign:grade', $this->context);
require_sesskey();
$instance = $this->get_instance();
$rownum = required_param('rownum', PARAM_INT);
$attemptnumber = optional_param('attemptnumber', -1, PARAM_INT);
$useridlistid = optional_param('useridlistid', time(), PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
$cache = cache::make_from_params(cache_store::MODE_SESSION, 'mod_assign', 'useridlist');
if (!$userid) {
if (!$useridlist = $cache->get($this->get_course_module()->id . '_' . $useridlistid)) {
$useridlist = $this->get_grading_userid_list();
$cache->set($this->get_course_module()->id . '_' . $useridlistid, $useridlist);
}
} else {
$useridlist = array($userid);
$rownum = 0;
}
$last = false;
$userid = $useridlist[$rownum];
if ($rownum == count($useridlist) - 1) {
$last = true;
}
$data = new stdClass();
$gradeformparams = array('rownum'=>$rownum,
'useridlistid'=>$useridlistid,
'last'=>false,
'attemptnumber'=>$attemptnumber,
'userid'=>optional_param('userid', 0, PARAM_INT));
$mform = new mod_assign_grade_form(null,
array($this, $data, $gradeformparams),
'post',
'',
array('class'=>'gradeform'));
if ($formdata = $mform->get_data()) {
$submission = null;
if ($instance->teamsubmission) {
$submission = $this->get_group_submission($userid, 0, false, $attemptnumber);
} else {
$submission = $this->get_user_submission($userid, false, $attemptnumber);
}
if ($instance->teamsubmission && $formdata->applytoall) {
$groupid = 0;
if ($this->get_submission_group($userid)) {
$group = $this->get_submission_group($userid);
if ($group) {
$groupid = $group->id;
}
}
$members = $this->get_submission_group_members($groupid, true);
foreach ($members as $member) {
// User may exist in multple groups (which should put them in the default group).
$this->apply_grade_to_user($formdata, $member->id, $attemptnumber);
$this->process_outcomes($member->id, $formdata);
}
} else {
$this->apply_grade_to_user($formdata, $userid, $attemptnumber);
$this->process_outcomes($userid, $formdata);
}
$maxattemptsreached = !empty($submission) &&
$submission->attemptnumber >= ($instance->maxattempts - 1) &&
$instance->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS;
$shouldreopen = false;
if ($instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS) {
// Check the gradetopass from the gradebook.
$gradinginfo = grade_get_grades($this->get_course()->id,
'mod',
'assign',
$instance->id,
$userid);
// What do we do if the grade has not been added to the gradebook (e.g. blind marking)?
$gradingitem = null;
$gradebookgrade = null;
if (isset($gradinginfo->items[0])) {
$gradingitem = $gradinginfo->items[0];
$gradebookgrade = $gradingitem->grades[$userid];
}
if ($gradebookgrade) {
// TODO: This code should call grade_grade->is_passed().
$shouldreopen = true;
if (is_null($gradebookgrade->grade)) {
//.........这里部分代码省略.........
示例5: bigbluebuttonbn_bbb_broker_get_meeting_info
function bigbluebuttonbn_bbb_broker_get_meeting_info($meetingid, $password, $forced = false)
{
global $CFG;
$meeting_info = array();
$endpoint = bigbluebuttonbn_get_cfg_server_url();
$shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
$cache_ttl = bigbluebuttonbn_get_cfg_waitformoderator_cache_ttl();
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'meetings_cache');
$result = $cache->get($meetingid);
$now = time();
if (isset($result) && $now < $result['creation_time'] + $cache_ttl && !$forced) {
//Use the value in the cache
$meeting_info = json_decode($result['meeting_info']);
} else {
//Ping again and refresh the cache
$meeting_info = (array) bigbluebuttonbn_getMeetingInfo($meetingid, $password, $endpoint, $shared_secret);
$cache->set($meetingid, array('creation_time' => time(), 'meeting_info' => json_encode($meeting_info)));
}
return $meeting_info;
}
示例6: process_save_grade
/**
* Save grade.
*
* @param moodleform $mform
* @return bool - was the grade saved
*/
protected function process_save_grade(&$mform)
{
global $CFG;
// Include grade form.
require_once $CFG->dirroot . '/mod/assign/gradeform.php';
require_sesskey();
$instance = $this->get_instance();
$rownum = required_param('rownum', PARAM_INT);
$attemptnumber = optional_param('attemptnumber', -1, PARAM_INT);
$useridlistid = optional_param('useridlistid', $this->get_useridlist_key_id(), PARAM_ALPHANUM);
$userid = optional_param('userid', 0, PARAM_INT);
$cache = cache::make_from_params(cache_store::MODE_SESSION, 'mod_assign', 'useridlist');
if (!$userid) {
if (!($useridlist = $cache->get($this->get_useridlist_key($useridlistid)))) {
// If the userid list is not cached we must not save, as it is possible that the user in a
// given row position may not be the same now as when the grading page was generated.
$url = new moodle_url('/mod/assign/view.php', array('id' => $this->get_course_module()->id));
throw new moodle_exception('useridlistnotcached', 'mod_assign', $url);
}
} else {
$useridlist = array($userid);
$rownum = 0;
}
$last = false;
$userid = $useridlist[$rownum];
if ($rownum == count($useridlist) - 1) {
$last = true;
}
$data = new stdClass();
$gradeformparams = array('rownum' => $rownum, 'useridlistid' => $useridlistid, 'last' => false, 'attemptnumber' => $attemptnumber, 'userid' => optional_param('userid', 0, PARAM_INT));
$mform = new mod_assign_grade_form(null, array($this, $data, $gradeformparams), 'post', '', array('class' => 'gradeform'));
if ($formdata = $mform->get_data()) {
return $this->save_grade($userid, $formdata);
} else {
return false;
}
}
示例7: 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));
}
示例8: __construct
/**
* Create new instance of string manager
*
* @param string $otherroot location of downlaoded lang packs - usually $CFG->dataroot/lang
* @param string $localroot usually the same as $otherroot
* @param bool $usecache use disk cache
* @param array $translist limit list of visible translations
* @param string $menucache the location of a file that caches the list of available translations
*/
public function __construct($otherroot, $localroot, $usecache, $translist, $menucache) {
$this->otherroot = $otherroot;
$this->localroot = $localroot;
$this->usecache = $usecache;
$this->translist = $translist;
$this->menucache = $menucache;
if ($this->usecache) {
// We can use a proper cache, establish the cache using the 'String cache' definition.
$this->cache = cache::make('core', 'string');
} else {
// We only want a cache for the length of the request, create a static cache.
$this->cache = cache::make_from_params(cache_store::MODE_REQUEST, 'core', 'string');
}
}
示例9: test_useridlist_cache
/**
* Test that the useridlist cache will retive the correct values
* when using assign::get_useridlist_key and assign::get_useridlist_key_id.
*/
public function test_useridlist_cache()
{
// Create an assignment object, we will use this to test the key generation functions.
$course = self::getDataGenerator()->create_course();
$assign = self::getDataGenerator()->create_module('assign', array('course' => $course->id));
list($courserecord, $cm) = get_course_and_cm_from_instance($assign->id, 'assign');
$context = context_module::instance($cm->id);
$assign = new assign($context, $cm, $courserecord);
// Create the cache.
$cache = cache::make_from_params(cache_store::MODE_SESSION, 'mod_assign', 'useridlist');
// Create an entry that we will insert into the cache.
$entry = array(0 => '5', 1 => '6325', 2 => '67783');
// Insert the value into the cache.
$cache->set($assign->get_useridlist_key(), $entry);
// Now test we can retrive the entry.
$this->assertEquals($entry, $cache->get($assign->get_useridlist_key()));
$useridlistid = clean_param($assign->get_useridlist_key_id(), PARAM_ALPHANUM);
$this->assertEquals($entry, $cache->get($assign->get_useridlist_key($useridlistid)));
// Check it will not retrive anything on an invalid key.
$this->assertFalse($cache->get($assign->get_useridlist_key('notvalid')));
}
示例10: bigbluebuttonbn_pluginfile
/**
* Serves the bigbluebuttonbn attachments. Implements needed access control ;-)
*
* @package mod_bigbluebuttonbn
* @category files
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool false if file not found, does not return if found - justsend the file
*/
function bigbluebuttonbn_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
global $CFG, $DB;
if ($context->contextlevel != CONTEXT_MODULE) {
return false;
}
$fileareas = bigbluebuttonbn_get_file_areas();
if (!array_key_exists($filearea, $fileareas)) {
return false;
}
if (!($bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance)))) {
return false;
}
if (sizeof($args) > 1) {
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'presentation_cache');
$presentation_nonce_key = sha1($bigbluebuttonbn->id);
$presentation_nonce = $cache->get($presentation_nonce_key);
$presentation_nonce_value = $presentation_nonce['value'];
$presentation_nonce_counter = $presentation_nonce['counter'];
if ($args["0"] != $presentation_nonce_value) {
return false;
}
//The nonce value is actually used twice because BigBlueButton reads the file two times
$presentation_nonce_counter += 1;
if ($presentation_nonce_counter < 2) {
$cache->set($presentation_nonce_key, array("value" => $presentation_nonce_value, "counter" => $presentation_nonce_counter));
} else {
$cache->delete($presentation_nonce_key);
}
$filename = $args["1"];
} else {
require_course_login($course, true, $cm);
if (!has_capability('mod/bigbluebuttonbn:join', $context)) {
return false;
}
$filename = implode('/', $args);
}
if ($filearea === 'presentation') {
$fullpath = "/{$context->id}/mod_bigbluebuttonbn/{$filearea}/0/" . $filename;
} else {
return false;
}
$fs = get_file_storage();
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
return false;
}
// finally send the file
send_stored_file($file, 0, 0, $forcedownload, $options);
// download MUST be forced - security!
}
示例11: add_to_log
} else {
if (version_compare($version, '2.7') < 0) {
// Log report action
add_to_log($course->id, 'elang', 'view report', 'mod/elang/view.php?id=' . $cm->id, 'all', $cm->id, $USER->id);
} else {
// Log this request.
$params = array('context' => $context, 'courseid' => $course->id, 'other' => array('action' => 'all'));
$event = \mod_elang\event\report_viewed::create($params);
$event->trigger();
}
// Output starts here.
echo $OUTPUT->header();
// Create the form
$mform = new mod_elang_report_form((string) new moodle_url('/mod/elang/view.php', array('id' => $cm->id)));
// Create the session cache
$cache = cache::make_from_params(cache_store::MODE_SESSION, 'mod_elang', 'useridlist');
// Get the date from the form
if ($fromform = $mform->get_data()) {
$perpage = $fromform->perpage;
$id_group = $fromform->group;
// Store the data in the session
$cache->set('perpage', $perpage);
$cache->set('id_group', $id_group);
} else {
// Get the data from the session or get the default
if ($cache->has('perpage')) {
$perpage = $cache->get('perpage');
} else {
$perpage = 20;
}
if ($cache->has('id_group')) {
示例12: test_default_request_cache
/**
* Tests the default request cache
*/
public function test_default_request_cache()
{
$cache = cache::make_from_params(cache_store::MODE_REQUEST, 'phpunit', 'applicationtest');
$this->assertInstanceOf('cache_request', $cache);
$this->run_on_cache($cache);
}
示例13: css_send_css_not_found
// Alternative theme location contains this theme - ok.
} else {
css_send_css_not_found();
}
}
$theme = theme_config::load($themename);
$theme->force_svg_use($usesvg);
if ($type === 'editor') {
$csscontent = $theme->get_css_content_editor();
css_send_uncached_css($csscontent);
}
$chunkurl = new moodle_url($CFG->httpswwwroot . '/theme/styles_debug.php', array('theme' => $themename, 'type' => $type, 'subtype' => $subtype, 'sheet' => $sheet, 'usesvg' => $usesvg));
// We need some kind of caching here because otherwise the page navigation becomes
// way too slow in theme designer mode. Feel free to create full cache definition later...
$key = "{$type} {$subtype} {$sheet} {$usesvg}";
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'core', 'themedesigner', array('theme' => $themename));
if ($content = $cache->get($key)) {
if ($content['created'] > time() - THEME_DESIGNER_CACHE_LIFETIME) {
$csscontent = $content['data'];
// We need to chunk the content.
if ($chunk !== null) {
$chunks = css_chunk_by_selector_count($csscontent, $chunkurl->out(false));
$csscontent = $chunk === 0 ? end($chunks) : $chunks[$chunk - 1];
}
css_send_uncached_css($csscontent);
}
}
$csscontent = $theme->get_css_content_debug($type, $subtype, $sheet);
$cache->set($key, array('data' => $csscontent, 'created' => time()));
// We need to chunk the content.
if ($chunk !== null) {
示例14: get_css_files
/**
* Returns an array of organised CSS files required for this output.
*
* @param bool $themedesigner
* @return array nested array of file paths
*/
protected function get_css_files($themedesigner)
{
global $CFG;
$cache = null;
$cachekey = 'cssfiles';
if ($themedesigner) {
require_once $CFG->dirroot . '/lib/csslib.php';
// We need some kind of caching here because otherwise the page navigation becomes
// way too slow in theme designer mode. Feel free to create full cache definition later...
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'core', 'themedesigner', array('theme' => $this->name));
if ($files = $cache->get($cachekey)) {
if ($files['created'] > time() - THEME_DESIGNER_CACHE_LIFETIME) {
unset($files['created']);
return $files;
}
}
}
$cssfiles = array('plugins' => array(), 'parents' => array(), 'theme' => array());
// Get all plugin sheets.
$excludes = $this->resolve_excludes('plugins_exclude_sheets');
if ($excludes !== true) {
foreach (core_component::get_plugin_types() as $type => $unused) {
if ($type === 'theme' || (!empty($excludes[$type]) and $excludes[$type] === true)) {
continue;
}
$plugins = core_component::get_plugin_list($type);
foreach ($plugins as $plugin => $fulldir) {
if (!empty($excludes[$type]) and is_array($excludes[$type]) and in_array($plugin, $excludes[$type])) {
continue;
}
// Get the CSS from the plugin.
$sheetfile = "{$fulldir}/styles.css";
if (is_readable($sheetfile)) {
$cssfiles['plugins'][$type . '_' . $plugin] = $sheetfile;
}
// Create a list of candidate sheets from parents (direct parent last) and current theme.
$candidates = array();
foreach (array_reverse($this->parent_configs) as $parent_config) {
$candidates[] = $parent_config->name;
}
$candidates[] = $this->name;
// Add the sheets found.
foreach ($candidates as $candidate) {
$sheetthemefile = "{$fulldir}/styles_{$candidate}.css";
if (is_readable($sheetthemefile)) {
$cssfiles['plugins'][$type . '_' . $plugin . '_' . $candidate] = $sheetthemefile;
}
}
}
}
}
// Find out wanted parent sheets.
$excludes = $this->resolve_excludes('parents_exclude_sheets');
if ($excludes !== true) {
foreach (array_reverse($this->parent_configs) as $parent_config) {
// Base first, the immediate parent last.
$parent = $parent_config->name;
if (empty($parent_config->sheets) || (!empty($excludes[$parent]) and $excludes[$parent] === true)) {
continue;
}
foreach ($parent_config->sheets as $sheet) {
if (!empty($excludes[$parent]) && is_array($excludes[$parent]) && in_array($sheet, $excludes[$parent])) {
continue;
}
// We never refer to the parent LESS files.
$sheetfile = "{$parent_config->dir}/style/{$sheet}.css";
if (is_readable($sheetfile)) {
$cssfiles['parents'][$parent][$sheet] = $sheetfile;
}
}
}
}
// Current theme sheets and less file.
// We first add the LESS files because we want the CSS ones to be included after the
// LESS code. However, if both the LESS file and the CSS file share the same name,
// the CSS file is ignored.
if (!empty($this->lessfile)) {
$sheetfile = "{$this->dir}/less/{$this->lessfile}.less";
if (is_readable($sheetfile)) {
$cssfiles['theme'][$this->lessfile] = $sheetfile;
}
}
if (is_array($this->sheets)) {
foreach ($this->sheets as $sheet) {
$sheetfile = "{$this->dir}/style/{$sheet}.css";
if (is_readable($sheetfile) && !isset($cssfiles['theme'][$sheet])) {
$cssfiles['theme'][$sheet] = $sheetfile;
}
}
}
if ($cache) {
$files = $cssfiles;
$files['created'] = time();
$cache->set($cachekey, $files);
//.........这里部分代码省略.........
示例15: test_session_cache_switch_user_multiple
/**
* Test multiple session caches when switching user.
*/
public function test_session_cache_switch_user_multiple()
{
$this->resetAfterTest(true);
$cache1 = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'sessioncache1');
$cache2 = cache::make_from_params(cache_store::MODE_SESSION, 'phpunit', 'sessioncache2');
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
// Log in as the first user.
$this->setUser($user1);
$sesskey1 = sesskey();
// Set a basic value in the caches.
$cache1->set('var', 1);
$cache2->set('var', 2);
$this->assertEquals(1, $cache1->get('var'));
$this->assertEquals(2, $cache2->get('var'));
// Change to the second user.
$this->setUser($user2);
$sesskey2 = sesskey();
// Make sure the cache doesn't give us the data for the last user.
// Also make sure that switching the user has lead to both caches being purged.
$this->assertNotEquals($sesskey1, $sesskey2);
$this->assertEquals(false, $cache1->get('var'));
$this->assertEquals(false, $cache2->get('var'));
}