Merge pull request #1427 from matrix-org/luke/feature-flair-cache-bust

Bust the flair caches after 30mins
pull/21833/head
David Baker 2017-09-25 15:39:06 +01:00 committed by GitHub
commit 2ab860f487
1 changed files with 9 additions and 1 deletions

View File

@ -29,6 +29,9 @@ const BULK_REQUEST_DEBOUNCE_MS = 200;
// If true, flair can function and we should keep sending requests for groups and avatars. // If true, flair can function and we should keep sending requests for groups and avatars.
let groupSupport = true; let groupSupport = true;
const USER_GROUPS_CACHE_BUST_MS = 1800000; // 30 mins
const GROUP_PROFILES_CACHE_BUST_MS = 1800000; // 30 mins
// TODO: Cache-busting based on time. (The server won't inform us of membership changes.) // TODO: Cache-busting based on time. (The server won't inform us of membership changes.)
// This applies to userGroups and groupProfiles. We can provide a slightly better UX by // This applies to userGroups and groupProfiles. We can provide a slightly better UX by
// cache-busting when the current user joins/leaves a group. // cache-busting when the current user joins/leaves a group.
@ -69,7 +72,9 @@ function getPublicisedGroupsCached(matrixClient, userId) {
usersPending[userId].reject = reject; usersPending[userId].reject = reject;
}).then((groups) => { }).then((groups) => {
userGroups[userId] = groups; userGroups[userId] = groups;
// TODO: Reset cache at this point setTimeout(() => {
delete userGroups[userId];
}, USER_GROUPS_CACHE_BUST_MS);
return userGroups[userId]; return userGroups[userId];
}).catch((err) => { }).catch((err) => {
throw err; throw err;
@ -126,6 +131,9 @@ async function getGroupProfileCached(matrixClient, groupId) {
groupId, groupId,
avatarUrl: profile.avatar_url, avatarUrl: profile.avatar_url,
}; };
setTimeout(() => {
delete groupProfiles[groupId];
}, GROUP_PROFILES_CACHE_BUST_MS);
return groupProfiles[groupId]; return groupProfiles[groupId];
} }