mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-16 21:30:32 +00:00
Update LRUCache.ts
Add a get function to the cache
This commit is contained in:
parent
61cfa0e86d
commit
eb84e2f8c9
@ -1,4 +1,4 @@
|
|||||||
import { logError, logDebug } from '@/common/utils/log';
|
import { logError, logDebug } from "@/common/utils/log";
|
||||||
|
|
||||||
type group_id = number;
|
type group_id = number;
|
||||||
type user_id = number;
|
type user_id = number;
|
||||||
@ -44,7 +44,7 @@ class LRU<T> {
|
|||||||
// 移除LRU节点
|
// 移除LRU节点
|
||||||
private removeLRUNode(node: cacheNode<T>) {
|
private removeLRUNode(node: cacheNode<T>) {
|
||||||
logDebug(
|
logDebug(
|
||||||
'removeLRUNode',
|
"removeLRUNode",
|
||||||
node.groupId,
|
node.groupId,
|
||||||
node.userId,
|
node.userId,
|
||||||
node.value,
|
node.value,
|
||||||
@ -140,6 +140,26 @@ class LRU<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public get(groupId: group_id): { userId: user_id; value: T }[];
|
||||||
|
public get(groupId: group_id, userId: user_id): null | { userId: user_id; value: T };
|
||||||
|
public get(groupId: group_id, userId?: user_id): any {
|
||||||
|
const groupObject = this.cache[groupId];
|
||||||
|
if(!groupObject) return userId === undefined ? [] : null;
|
||||||
|
|
||||||
|
if (userId === undefined) {
|
||||||
|
return Object.entries(groupObject).map(([userId, { value }]) => ({
|
||||||
|
userId: Number(userId),
|
||||||
|
value,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupObject[userId]) {
|
||||||
|
return { userId, value: groupObject[userId].value };
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LRU;
|
export default LRU;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user