-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { defineDriver } from "./utils"; | ||
import LRU, { SharedOptions as _LRUOptions } from "lru-cache"; | ||
|
||
type LRUOptions = _LRUOptions<string, any>; | ||
export interface LRUDriverOptions extends LRUOptions {} | ||
|
||
export default defineDriver((opts: LRUDriverOptions) => { | ||
const cache = new LRU({ | ||
...opts, | ||
maxSize: 500, | ||
}); | ||
|
||
return { | ||
hasItem(key) { | ||
return cache.has(key); | ||
}, | ||
getItem(key) { | ||
return cache.get(key) || null; | ||
}, | ||
getItemRaw(key) { | ||
return cache.get(key) || null; | ||
}, | ||
setItem(key, value) { | ||
cache.set(key, value); | ||
}, | ||
setItemRaw(key, value) { | ||
cache.set(key, value); | ||
}, | ||
removeItem(key) { | ||
cache.delete(key); | ||
}, | ||
getKeys() { | ||
return Array.from(cache.keys()); | ||
}, | ||
clear() { | ||
cache.clear(); | ||
}, | ||
dispose() { | ||
cache.clear(); | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters