tabby/app/lib/lru.ts

18 lines
437 B
TypeScript
Raw Normal View History

2021-12-07 02:13:26 +08:00
import LRU from 'lru-cache'
2020-02-05 20:16:31 +08:00
import * as fs from 'fs'
2020-12-24 21:03:14 +08:00
const lru = new LRU({ max: 256, maxAge: 250 })
2020-02-05 20:16:31 +08:00
const origLstat = fs.realpathSync.bind(fs)
// NB: The biggest offender of thrashing realpathSync is the node module system
// itself, which we can't get into via any sane means.
require('fs').realpathSync = function (p) {
let r = lru.get(p)
2020-02-05 20:16:31 +08:00
if (r) {
return r
}
r = origLstat(p)
lru.set(p, r)
return r
}