mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
core: also del user cache when domain.user changes
This commit is contained in:
1 parent
7a343449b0
commit
a996b6b155
4 files changed
+24
-9
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user