Skip to content

Commit

Permalink
MDL-58590 mobile: Cache mobile-supporting plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
sk-unikent committed Apr 20, 2017
1 parent 0905763 commit e0b6925
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
12 changes: 11 additions & 1 deletion admin/tool/mobile/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public static function get_plugins_supporting_mobile() {
global $CFG;
require_once($CFG->libdir . '/adminlib.php');

// Check if we can return this from cache.
$cache = \cache::make('tool_mobile', 'plugininfo');
$pluginsinfo = $cache->get('mobileplugins');
if ($pluginsinfo !== false) {
return (array)$pluginsinfo;
}

$pluginsinfo = [];
$plugintypes = core_component::get_plugin_types();

Expand All @@ -68,7 +75,7 @@ public static function get_plugins_supporting_mobile() {
$component = $plugintype . '_' . $plugin;
$version = get_component_version($component);

require_once("$path/db/mobile.php");
require("$path/db/mobile.php");
foreach ($addons as $addonname => $addoninfo) {
$plugininfo = array(
'component' => $component,
Expand All @@ -91,6 +98,9 @@ public static function get_plugins_supporting_mobile() {
}
}
}

$cache->set('mobileplugins', $pluginsinfo);

return $pluginsinfo;
}

Expand Down
34 changes: 34 additions & 0 deletions admin/tool/mobile/db/caches.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Mobile cache definitions.
*
* @package tool_mobile
* @copyright 2017 Skylar Kelty <S.Kelty@kent.ac.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;

$definitions = array(
'plugininfo' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'staticacceleration' => true,
'staticaccelerationsize' => 1
)
);
1 change: 1 addition & 0 deletions admin/tool/mobile/lang/en/tool_mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

$string['autologinkeygenerationlockout'] = 'Auto-login key generation is blocked because of too many requests within an hour.';
$string['autologinnotallowedtoadmins'] = 'Auto-login is not allowed for site admins.';
$string['cachedef_plugininfo'] = 'This stores the list of plugins with mobile addons';
$string['clickheretolaunchtheapp'] = 'Click here if the app does not open automatically.';
$string['configmobilecssurl'] = 'A CSS file to customise your mobile app interface.';
$string['enablesmartappbanners'] = 'Enable Smart App Banners';
Expand Down

0 comments on commit e0b6925

Please sign in to comment.