fix: 加上 - 分隔符来避免跨前缀误匹配

master^2
layhuts 2026-05-09 12:56:50 +08:00
parent 1f584ff0c9
commit 9667232684
1 changed files with 4 additions and 2 deletions

View File

@ -27,7 +27,8 @@ class StorageManager {
*/
async clear(): Promise<void> {
const allKeys = await this.driver.keys();
const prefixedKeys = allKeys.filter((key) => key.startsWith(this.prefix));
const fullPrefix = this.prefix ? `${this.prefix}-` : '';
const prefixedKeys = allKeys.filter((key) => key.startsWith(fullPrefix));
await Promise.all(prefixedKeys.map((key) => this.driver.removeItem(key)));
}
@ -36,7 +37,8 @@ class StorageManager {
*/
async clearExpiredItems(): Promise<void> {
const allKeys = await this.driver.keys();
const prefixedKeys = allKeys.filter((key) => key.startsWith(this.prefix));
const fullPrefix = this.prefix ? `${this.prefix}-` : '';
const prefixedKeys = allKeys.filter((key) => key.startsWith(fullPrefix));
for (const fullKey of prefixedKeys) {
const raw = await this.driver.getItem<StorageItem<unknown>>(fullKey);