mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 08:22:07 +02:00
MDL-68677 core: Correct usage of templaterev for caching templates
The M.cfg.templaterev variable should only be used to present persistent caching, not caching of content within the same page load. Preventing caching of same-page content makes it difficult to develop for real user experiences as content is slow to load and does not give a realistic and consistent loading experience. This change affects the loading of partials specifically which notably includes the loading spinner. Without this patch the loading icon is often not seen at all because it does not load in a timely fashion and the content being loaded is loaded first.
This commit is contained in:
parent
206e179df5
commit
b9dec51ab4
2
lib/amd/build/templates.min.js
vendored
2
lib/amd/build/templates.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -79,11 +79,6 @@ define([
|
||||
* @return {Object} jQuery promise resolved with the template source
|
||||
*/
|
||||
var getTemplatePromiseFromCache = function(searchKey) {
|
||||
// Do not cache anything if templaterev is not valid.
|
||||
if (M.cfg.templaterev <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// First try the cache of promises.
|
||||
if (searchKey in templatePromises) {
|
||||
return templatePromises[searchKey];
|
||||
@ -96,6 +91,11 @@ define([
|
||||
return templatePromises[searchKey];
|
||||
}
|
||||
|
||||
if (M.cfg.templaterev <= 0) {
|
||||
// Template caching is disabled. Do not store in persistent storage.
|
||||
return null;
|
||||
}
|
||||
|
||||
// Now try local storage.
|
||||
var cached = storage.get('core_template/' + M.cfg.templaterev + ':' + searchKey);
|
||||
if (cached) {
|
||||
@ -183,7 +183,11 @@ define([
|
||||
// Cache all of the dependent templates because we'll need them to render
|
||||
// the requested template.
|
||||
templateCache[tempSearchKey] = data.value;
|
||||
storage.set('core_template/' + M.cfg.templaterev + ':' + tempSearchKey, data.value);
|
||||
|
||||
if (M.cfg.templaterev > 0) {
|
||||
// The template cache is enabled - set the value there.
|
||||
storage.set('core_template/' + M.cfg.templaterev + ':' + tempSearchKey, data.value);
|
||||
}
|
||||
|
||||
if (data.component == component && data.name == name) {
|
||||
// This is the original template that was requested so remember it to return.
|
||||
|
Loading…
x
Reference in New Issue
Block a user