FileChangedCache
This class caches information about files and determines whether they have changed contents or not. Most importantly, this class caches the hash of seen files so that at development time, we don't have to recalculate them constantly.
This class is also the core of how electron-compile runs quickly in production mode - after precompilation, the cache is serialized along with the rest of the data in CompilerHost, so that when we load the app in production mode, we don't end up calculating hashes of file content at all, only using the contents of this cache.
Static Method Summary
Static Public Methods | ||
public static |
loadFromData(data: Object, appRoot: string, failOnCacheMiss: boolean): FileChangedCache Allows you to create a FileChangedCache from serialized data saved from getSavedData. |
|
public static |
loadFromFile(file: string, appRoot: string, failOnCacheMiss: boolean): FileChangedCache Allows you to create a FileChangedCache from serialized data saved from save. |
Constructor Summary
Public Constructor | ||
public |
constructor(appRoot: *, failOnCacheMiss: boolean) |
Member Summary
Public Members | ||
public |
appRoot: * |
|
public |
changeCache: * |
|
public |
|
Method Summary
Public Methods | ||
public |
calculateHashForFile(absoluteFilePath: *): * |
|
public |
calculateHashForFileSync(absoluteFilePath: *): * |
|
public |
getHashForPath(absoluteFilePath: string): Object Returns information about a given file, including its hash. |
|
public |
getHashForPathSync(absoluteFilePath: string): Object Returns information about a given file, including its hash. |
|
public |
Returns data that can passed to loadFromData to rehydrate this cache. |
|
public |
Serializes this object's data to a file. |
|
public |
Serializes this object's data to a file. |
Static Public Methods
public static loadFromData(data: Object, appRoot: string, failOnCacheMiss: boolean): FileChangedCache source
Allows you to create a FileChangedCache from serialized data saved from getSavedData.
Public Constructors
Public Members
public appRoot: * source
public changeCache: * source
public failOnCacheMiss: * source
Public Methods
public calculateHashForFile(absoluteFilePath: *): * source
Params:
Name | Type | Attribute | Description |
absoluteFilePath | * |
Return:
* |
public calculateHashForFileSync(absoluteFilePath: *): * source
Params:
Name | Type | Attribute | Description |
absoluteFilePath | * |
Return:
* |
public getHashForPath(absoluteFilePath: string): Object source
Returns information about a given file, including its hash. This method is the main method for this cache.
Params:
Name | Type | Attribute | Description |
absoluteFilePath | string | The path to a file to retrieve info on. |
Return:
Object |
Return Properties:
Name | Type | Attribute | Description |
hash | string | The SHA1 hash of the file |
|
isMinified | boolean | True if the file is minified |
|
isInNodeModules | boolean | True if the file is in a library directory |
|
hasSourceMap | boolean | True if the file has a source map |
|
isFileBinary | boolean | True if the file is not a text file |
|
binaryData | Buffer | (optional) The buffer that was read if the file was binary and there was a cache miss. |
|
code | string | (optional) The string that was read if the file was text and there was a cache miss |
public getHashForPathSync(absoluteFilePath: string): Object source
Returns information about a given file, including its hash. This method is the main method for this cache.
Params:
Name | Type | Attribute | Description |
absoluteFilePath | string | The path to a file to retrieve info on. |
Return:
Object |
Return Properties:
Name | Type | Attribute | Description |
hash | string | The SHA1 hash of the file |
|
isMinified | boolean | True if the file is minified |
|
isInNodeModules | boolean | True if the file is in a library directory |
|
hasSourceMap | boolean | True if the file has a source map |
|
isFileBinary | boolean | True if the file is not a text file |
|
binaryData | Buffer | (optional) The buffer that was read if the file was binary and there was a cache miss. |
|
code | string | (optional) The string that was read if the file was text and there was a cache miss |
public getSavedData(): Object source
Returns data that can passed to loadFromData to rehydrate this cache.