Skip to content

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

NameTypeDescription
[opts]TemplateFileOptsThe TemplateFileOpts
[readFormatter]functionThe function(string, readFormatOptions) that will return a formatted string for reading
data using the options.readFormatOptions from TemplateOpts as the formatting options. Typically reads are for HTML
minification 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]functionThe function(string, writeFormatOptions) that will return a formatted string for writting
data using the options.writeFormatOptions from TemplateOpts as the formatting options. Typically reads are for JS
minification 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]ObjectThe log for handling logging output
[log.debug]functionA function that will accept debug level logging messages (i.e. debug('some message to log'))
[log.info]functionA function that will accept info level logging messages (i.e. info('some message to log'))
[log.warn]functionA function that will accept warning level logging messages (i.e. warn('some message to log'))
[log.error]functionA 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

NameTypeDescription
[read]BooleanWhen 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[].nameStringThe name that uniquely identifies the template, partial or context
[partials[].content]StringThe raw content that will be registered. Omit when read === true to read content from cache.
[partials[].params]URLSearchParamsThe URLSearchParams that will be passed during the content read
(ignored when content is specified).
[partials[].extension]StringOptional override for a file extension designated for a template, partial or context.
[read]BooleanWhen true, an attempt will be made to also Cachier.read the template, partials and context that
do not have a content property set.
[write]BooleanWhen true, an attempt will be made to also Cachier.write the template, partials and context that
have a content property set.

Returns

  • Object — An object that contains the registration results:

  • data The object that contains the template, partial fragments and/or context that have been registered

    • name The name that uniquely identifies the template, partial or context
    • content The raw content of the template, partial or context
    • extension The template file extension designation
    • params The URLSearchParams passed during the initial content read
    • fromRead A flag that indicates that the data was set from a read operation
    • overrideFromFileRead A flag that indicates if the passed partial content was overridden by content from a file read
  • dirs Contains the directories/sub-directories that were created

cachierFiles.compile()

Async: yes

cachierFiles.read()

Async: yes

cachierFiles.write()

Async: yes

cachierFiles.metadata

cachierFiles.statsObject

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

NameTypeDefaultDescription
[all=false]Booleanfalsetrue to clear all matching temporary output directories.

cachierFiles.clear([all=false])

Clears memory, generated files and file watchers.

Async: yes

Parameters

NameTypeDefaultDescription
[all=false]Booleanfalsetrue to clear all temporary directories created over multiple instances.

cachierFiles.close()

Stops watchers and releases memory without deleting generated files.

Async: yes

cachierFiles.readWriteNames

cachierFiles.operations

Released under the MIT License.