Skip to content

Instantly share code, notes, and snippets.

@marinaglancy
Created February 22, 2013 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marinaglancy/5011144 to your computer and use it in GitHub Desktop.
Save marinaglancy/5011144 to your computer and use it in GitHub Desktop.
<?php
require("config.php");
require_login();
$PAGE->set_course($SITE);
$url = new moodle_url('/sessioncache.php');
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
$PAGE->set_title($SITE->fullname);
$PAGE->set_heading($SITE->fullname);
$cache = cache::make_from_params(cache_store::MODE_SESSION, 'core', 'testsessioncache');
$action = optional_param('cache', null, PARAM_RAW);
if ($action === 'set') {
$cache->set('var', '[ '. $USER->id.' : '.sesskey(). ' : '. date('H:i:s').' ]');
redirect($url);
} else if ($action === 'purge') {
$cache->purge();
redirect($url);
}
echo $OUTPUT->header();
$str = array();
$str[] = 'Your user id is <b>'.$USER->id. '</b>';
$str[] = 'Your sesskey is <b>'.sesskey(). '</b>';
$str[] = 'Your cache contents is <b>'.$cache->get('var'). '</b>';
echo html_writer::tag('div', join('<br>', $str));
echo html_writer::tag('div','&nbsp;');
echo html_writer::tag('div', html_writer::link($url->out(true, array('tm' => time())), 'Refresh page'));
echo html_writer::tag('div','&nbsp;');
echo html_writer::tag('div', html_writer::link($url->out(true, array('cache' => 'set')), 'Set cache'));
echo html_writer::tag('div','&nbsp;');
echo html_writer::tag('div', html_writer::link($url->out(true, array('cache' => 'purge')), 'Purge cache'));
echo $OUTPUT->footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment