Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Moodle Cache API for Slides #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions classes/output/core_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,16 +1144,16 @@ public function matomo_insert_html() {
* @return string
*/
public function slideshow() {
global $CFG, $USER;
global $CFG;

$output = '';

if (file_exists($CFG->dirroot . '/local/marketing/locallib.php')) {
$cache = \cache::make('theme_wwu2019', 'slides');
$slides = $cache->get('slides');
// Retrieve slides if none are cached.
// Also, force re-cache if user has changed ID recently (i.e., a login has occurred).
if (!isset($_SESSION["theme_wwu2019_slides"]) || !is_array($_SESSION["theme_wwu2019_slides"]) ||
$_SESSION["theme_wwu2019_slides_cachedfor"] !== $USER->id || empty($_SESSION["theme_wwu2019_slides"])
) {
if ($slides === false) {
require_once($CFG->dirroot . '/local/marketing/locallib.php');
$allslides = \local_marketing\slide_manager::get_slides_for();
$slides = array();
Expand Down Expand Up @@ -1185,10 +1185,7 @@ public function slideshow() {
$slides[0]->active = true;
}

$_SESSION["theme_wwu2019_slides"] = $slides;
$_SESSION["theme_wwu2019_slides_cachedfor"] = $USER->id;
} else {
$slides = $_SESSION["theme_wwu2019_slides"];
$cache->set('slides', $slides);
}

if ($slides) {
Expand Down
4 changes: 4 additions & 0 deletions db/caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@
'staticacceleration' => true,
'staticaccelerationsize' => 1
),
'slides' => array(
'mode' => cache_store::MODE_SESSION,
'simplekeys' => true
),

);
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
defined('MOODLE_INTERNAL') || die();

// This is the version of the plugin.
$plugin->version = 2020031600;
$plugin->version = 2021082000;

// This is the version of Moodle this plugin requires.
$plugin->requires = 2019111800.03;
Expand Down