CachierFiles
new CachierFiles([opts], [readFormatter], [writeFormatter], [log])
Node.js [file]https://nodejs.org/api/fs.html persistence manager that uses the file system for improved debugging/caching capabilities
Parameters
| Name | Type | Description |
|---|---|---|
| [opts] | TemplateFileOpts | The TemplateFileOpts |
| [readFormatter] | function | The function(string, readFormatOptions) that will return a formatted string for readingdata using the options.readFormatOptions from TemplateOpts as the formatting options. Typically reads are for HTMLminification and/or beautifying. NOTE: Use with caution as syntax errors may result depending on the formatter used and the complexity of the data being formatted! |
| [writeFormatter] | function | The function(string, writeFormatOptions) that will return a formatted string for writtingdata using the options.writeFormatOptions from TemplateOpts as the formatting options. Typically reads are for JSminification and/or beautifying. NOTE: Use with caution as syntax errors may result depending on the formatter used and the complexity of the data being formatted! |
| [log] | Object | The log for handling logging output |
| [log.debug] | function | A function that will accept debug level logging messages (i.e. debug('some message to log')) |
| [log.info] | function | A function that will accept info level logging messages (i.e. info('some message to log')) |
| [log.warn] | function | A function that will accept warning level logging messages (i.e. warn('some message to log')) |
| [log.error] | function | A function that will accept error level logging messages (i.e. error('some message to log')) |
cachierFiles.register([read], [data], [read], [write]) ⇒ Object
Registers and caches the tempalte, one or more partials and/or context within the internal file system. Also creates any missing directories/sub-directories within the TemplateFileOpts outputPath directory from partialsPath sub-directories.
Async: yes
Parameters
| Name | Type | Description |
|---|---|---|
| [read] | Boolean | When true, an attempt will be made to also read any partials using option parameter |
| [data] | Array.<Object> | The template, partials and/or context to register. |
| partials[].name | String | The name that uniquely identifies the template, partial or context |
| [partials[].content] | String | The raw content that will be registered. Omit when read === true to read content from cache. |
| [partials[].params] | URLSearchParams | The URLSearchParams that will be passed during the content read(ignored when content is specified). |
| [partials[].extension] | String | Optional override for a file extension designated for a template, partial or context. |
| [read] | Boolean | When true, an attempt will be made to also Cachier.read the template, partials and context thatdo not have a content property set. |
| [write] | Boolean | When true, an attempt will be made to also Cachier.write the template, partials and context thathave a content property set. |
Returns
Object— An object that contains the registration results:dataThe object that contains the template, partial fragments and/or context that have been registerednameThe name that uniquely identifies the template, partial or contextcontentThe raw content of the template, partial or contextextensionThe template file extension designationparamsThe URLSearchParams passed during the initial content readfromReadA flag that indicates that the data was set from a read operationoverrideFromFileReadA flag that indicates if the passed partial content was overridden by content from a file read
dirsContains the directories/sub-directories that were created
cachierFiles.compile()
Async: yes
cachierFiles.read()
Async: yes
cachierFiles.write()
Async: yes
cachierFiles.metadata
cachierFiles.stats ⇒ Object
Returns
Object— Combined memory-cache and file-watcher statistics.
cachierFiles.resetStats() ⇒ Object
Returns
Object— The reset combined statistics.
cachierFiles.clearMemory()
Clears in-memory template content and compiled renderers while preserving watcher and directory state.
Async: yes
cachierFiles.startWatching() ⇒ Number
Starts native watchers for partialsPath and reconciles the current partial tree.
Async: yes
Returns
Number— The number of active directory watchers.
cachierFiles.reconcileWatching() ⇒ Number
Reconciles watched files and directories with the current file system.
Async: yes
Returns
Number— The number of files discovered during reconciliation.
cachierFiles.stopWatching() ⇒ Number
Stops all compile-time file watchers and pending watcher work.
Async: yes
Returns
Number— The number of closed watchers.
cachierFiles.clearGeneratedFiles([all=false])
Clears generated renderer files without clearing in-memory cache entries.
Async: yes
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| [all=false] | Boolean | false | true to clear all matching temporary output directories. |
cachierFiles.clear([all=false])
Clears memory, generated files and file watchers.
Async: yes
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| [all=false] | Boolean | false | true to clear all temporary directories created over multiple instances. |
cachierFiles.close()
Stops watchers and releases memory without deleting generated files.
Async: yes