@speedy/require-cache
Version:
Speed up Node load time by caching resolved module paths to avoid module resolution and refetching each time the application is loaded.
60 lines (59 loc) • 1.62 kB
TypeScript
import { CacheOptions, CacheStats } from "./require-cache.model";
/**
* Speed up Node load time by caching resolved module paths to avoid Node refetching
* and resolving the modules each time the application is loaded.
*
* The first time the application loads, a cache of resolved file paths is saved in the file system.
*
* @example
* import { RequireCache } from "@speedy/require-cache";
* new RequireCache().start();
*
* import * as stylelint from "stylelint";
* import * as _ from "lodash";
*
* @class RequireCache
*/
export declare class RequireCache {
private isCacheModified;
private logger;
private resolveFileNameOriginal;
private cwd;
private filesLookUp;
private _options;
private _isEnabled;
private _stats;
/**
* Creates an instance of RequireCache.
* @param {Partial<CacheOptions>} [options]
*/
constructor(options?: Partial<CacheOptions>);
/**
* Start caching of module locations.
*
* @returns {RequireCache}
*/
start(): RequireCache;
/** Stop caching of the modules locations. */
stop(): void;
/** Deletes the cache file. */
reset(): void;
/** Saves cached paths to file. */
save(): void;
/**
* Whether or not the cache is currently enabled.
*
* @readonly
* @type {boolean}
*/
readonly isEnabled: boolean;
/**
* Caching effectiveness statistics.
*
* @readonly
* @type {CacheStats}
*/
readonly stats: CacheStats;
private resolveFilenameOptimized(path, parentModule);
private getCacheKey(path, filename);
}