mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-19 06:20:38 -07:00
feat: async cache.read()/write(), remove .has()
This commit is contained in:
Vendored
+2
-3
@@ -1,5 +1,4 @@
|
||||
export interface Cache<T> {
|
||||
write (key: string, value: T): void;
|
||||
read (key: string): T | undefined;
|
||||
has (key: string): boolean;
|
||||
write (key: string, value: T): void | Promise<void>;
|
||||
read (key: string): T | undefined | Promise<T | undefined>;
|
||||
}
|
||||
|
||||
Vendored
-4
@@ -42,10 +42,6 @@ export class LRU<T> implements Cache<T> {
|
||||
return value
|
||||
}
|
||||
|
||||
has (key: string): boolean {
|
||||
return !!this.cache[key]
|
||||
}
|
||||
|
||||
remove (key: string) {
|
||||
const node = this.cache[key]
|
||||
node.prev.next = node.next
|
||||
|
||||
+5
-2
@@ -76,10 +76,13 @@ export class Liquid {
|
||||
|
||||
for (const filepath of paths) {
|
||||
const { cache } = this.options
|
||||
if (cache && cache.has(filepath)) return cache.read(filepath)
|
||||
if (cache) {
|
||||
const tpls = yield cache.read(filepath)
|
||||
if (tpls) return tpls
|
||||
}
|
||||
if (!(sync ? this.fs.existsSync(filepath) : yield this.fs.exists(filepath))) continue
|
||||
const tpl = this.parse(sync ? this.fs.readFileSync(filepath) : yield this.fs.readFile(filepath), filepath)
|
||||
cache && cache.write(filepath, tpl)
|
||||
if (cache) cache.write(filepath, tpl)
|
||||
return tpl
|
||||
}
|
||||
throw this.lookupError(file, options.root)
|
||||
|
||||
Reference in New Issue
Block a user