This repository has been archived by the owner on Mar 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: better management of cache (#83)
* better management of cache * add caching for templates
- Loading branch information
1 parent
c9627b3
commit bd91ba1
Showing
9 changed files
with
14 additions
and
79 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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 5 additions & 6 deletions
11
src/utils/sfc-parser.ts → src/utils/cacher.ts
100755 → 100644
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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
import { parseComponent, SFCDescriptor } from 'vue-template-compiler' | ||
// tslint:disable-next-line:no-var-requires | ||
const LRUCache = require('lru-cache') | ||
// tslint:disable-next-line:no-var-requires | ||
const hash = require('hash-sum') | ||
|
||
const cache = new LRUCache(250) | ||
|
||
export default function scfParser(source: string, filename: string): SFCDescriptor { | ||
const hashTmp = hash | ||
const cacheKey = hashTmp(filename + source) | ||
export default function<T>(creator: () => T, ...argsKey: string[]): T { | ||
const cacheKey = hash(argsKey.join('')) | ||
|
||
// source-map cache busting for hot-reloadded modules | ||
let output: SFCDescriptor = cache.get(cacheKey) | ||
let output: T = cache.get(cacheKey) | ||
if (output) { | ||
return output | ||
} | ||
output = parseComponent(source) | ||
output = creator() | ||
cache.set(cacheKey, output) | ||
return output | ||
} |
This file was deleted.
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