Skip to content

Commit

Permalink
Adding flag to enable or disable caching of lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyatt committed Jul 15, 2018
1 parent 3486640 commit eb3c606
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
28 changes: 19 additions & 9 deletions 2.4/blocks/aspirelists/block_aspirelists.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';

Expand Down
5 changes: 4 additions & 1 deletion 2.4/blocks/aspirelists/lang/en/block_aspirelists.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -63,4 +66,4 @@
$spuriousVar = 'î';

$string['cachedef_aspirelists'] = 'Talis Aspire reading lists';
$string['expirelisttask'] = 'Expire Talis Aspire list cache';
$string['expirelisttask'] = 'Expire Talis Aspire list cache';
2 changes: 2 additions & 0 deletions 2.4/blocks/aspirelists/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

0 comments on commit eb3c606

Please sign in to comment.