( pathFunction: (path: string) => TResult, )
| 223 | } |
| 224 | |
| 225 | function makeCheapPathFunction<TResult>( |
| 226 | pathFunction: (path: string) => TResult, |
| 227 | ): typeof pathFunction { |
| 228 | if (! ENABLED) { |
| 229 | return pathFunction; |
| 230 | } |
| 231 | const wrapper = wrap(pathFunction, { |
| 232 | // The maximum LRU cache size is Math.pow(2, 16) by default, but it's |
| 233 | // important to prevent eviction churn for very-frequently-called |
| 234 | // functions like optimisticStatOrNull. While it's tempting to set |
| 235 | // this limit to Infinity, increasing it by 16x comes close enough. |
| 236 | max: Math.pow(2, 20), |
| 237 | subscribe(path) { |
| 238 | let watcher: SafeWatcher | null = watch( |
| 239 | path, |
| 240 | () => wrapper.dirty(path), |
| 241 | ); |
| 242 | return function () { |
| 243 | if (watcher) { |
| 244 | watcher.close(); |
| 245 | watcher = null; |
| 246 | } |
| 247 | }; |
| 248 | } |
| 249 | }); |
| 250 | return wrapper; |
| 251 | } |
| 252 | |
| 253 | export const optimisticStatOrNull = makeCheapPathFunction( |
| 254 | (path: string) => { |
no test coverage detected
searching dependent graphs…