core: also del user cache when domain.user changes

This commit is contained in:
undefined committed 2021-05-04 12:32:26 +08:00
1 parent 7a343449b0
commit a996b6b155
4 files changed
+24 -9

No files matched your search

+6 -2
View File
@@ -19,8 +19,12 @@ const coll: Collection<Udoc> = db.collection('user');
const logger = new Logger('model/user');
const cache = new LRU<string, User>({ max: 500, maxAge: 300 * 1000 });
function deleteUserCache(udoc: User | Udoc) {
if (udoc) {
export function deleteUserCache(udoc: User | Udoc | string) {
if (typeof udoc === 'string') {
for (const key of cache.keys().filter((k) => k.endsWith(`/${udoc}`))) {
cache.del(key);
}
} else if (udoc) {
const id = [udoc._id.toString(), udoc.uname.toLowerCase(), udoc.mail.toLowerCase()];
for (const key of cache.keys().filter((k) => id.includes(k.split('/')[0]))) {
cache.del(key);