From eb3c606763cf749995ca5b21f6980915ffcfc21d Mon Sep 17 00:00:00 2001 From: Russell Boyatt Date: Sun, 15 Jul 2018 17:50:36 +0100 Subject: [PATCH] Adding flag to enable or disable caching of lists. --- 2.4/blocks/aspirelists/block_aspirelists.php | 28 +++++++++++++------ .../aspirelists/lang/en/block_aspirelists.php | 5 +++- 2.4/blocks/aspirelists/settings.php | 2 ++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/2.4/blocks/aspirelists/block_aspirelists.php b/2.4/blocks/aspirelists/block_aspirelists.php index f60ba40..e0ccdf2 100644 --- a/2.4/blocks/aspirelists/block_aspirelists.php +++ b/2.4/blocks/aspirelists/block_aspirelists.php @@ -24,18 +24,28 @@ function get_content() { $target = '_blank'; } - $this->content = new stdClass; + $this->content = new stdClass; - if ($COURSE->idnumber) - { - $cache = cache::make('block_aspirelists', 'aspirelists'); - $lists = $cache->get(block_aspirelists::CACHEPREFIX . $COURSE->idnumber); + $cachingEnabled = get_config('aspirelists', 'caching'); - if(!$lists) { - // get the code from the global course object + if ($COURSE->idnumber) + { + if($cachingEnabled) + { + $cache = cache::make('block_aspirelists', 'aspirelists'); + $lists = $cache->get(block_aspirelists::CACHEPREFIX . $COURSE->idnumber); + + if(!$lists) { + // get the code from the global course object + $lists = $this->getTalisAspireList($COURSE->idnumber); + $cache->set(block_aspirelists::CACHEPREFIX . $COURSE->idnumber, $lists); + } + } + else + { $lists = $this->getTalisAspireList($COURSE->idnumber); - $cache->set(block_aspirelists::CACHEPREFIX . $COURSE->idnumber, $lists); - } + } + $output = ''; diff --git a/2.4/blocks/aspirelists/lang/en/block_aspirelists.php b/2.4/blocks/aspirelists/lang/en/block_aspirelists.php index d2d79ea..d48828f 100644 --- a/2.4/blocks/aspirelists/lang/en/block_aspirelists.php +++ b/2.4/blocks/aspirelists/lang/en/block_aspirelists.php @@ -42,6 +42,9 @@ $string['config_noResourceListsMessage'] = 'Message: no lists available'; $string['config_noResourceListsMessage_desc'] = 'The text of the message to display when there are no lists available.'; +$string['config_caching'] = 'List caching'; +$string['config_caching_desc'] = 'Enables the caching of list data from Talis Aspire to improve performance.'; + $string['modules'] = 'Modules'; $string['courses'] = 'Courses'; $string['units'] = 'Units'; @@ -63,4 +66,4 @@ $spuriousVar = 'î'; $string['cachedef_aspirelists'] = 'Talis Aspire reading lists'; -$string['expirelisttask'] = 'Expire Talis Aspire list cache'; \ No newline at end of file +$string['expirelisttask'] = 'Expire Talis Aspire list cache'; diff --git a/2.4/blocks/aspirelists/settings.php b/2.4/blocks/aspirelists/settings.php index ac5bdab..64a9ba8 100644 --- a/2.4/blocks/aspirelists/settings.php +++ b/2.4/blocks/aspirelists/settings.php @@ -28,3 +28,5 @@ $settings->add(new admin_setting_configtext('aspirelists/blockTitle',get_string('config_AspireBlockTitle', 'block_aspirelists'),get_string('config_AspireBlockTitle_desc', 'block_aspirelists'), get_string('aspirelists', 'block_aspirelists') )); $settings->add(new admin_setting_configtext('aspirelists/noResourceListsMessage',get_string('config_noResourceListsMessage', 'block_aspirelists'),get_string('config_noResourceListsMessage_desc', 'block_aspirelists'), get_string('no_resource_lists_msg', 'block_aspirelists') )); + + $settings->add(new admin_setting_configcheckbox('aspirelists/caching', get_string('config_caching', 'block_aspirelists'), get_string('config_caching_desc', 'block_aspirelists'), 0));