Skip to content

CachierDB

new CachierDB([opts], [readFormatter], [writeFormatter], [log])

Persistence cache manager that uses an IndexedDB or LevelDB store for partial content and compilation segments. The type of DB used is first determined by the presence of an indexedDB on the global/window reference that contains either an IDBFactory or other supported IndexedDB-like interface (e.g. LevelUP). When an indexedDB reference is not present, an atempt to load a module using the options.dbTypeName as the module name/path that resolves into a function that takes a location path from options.dbLocName as it's first argument.

Parameters

NameTypeDescription
[opts]TemplateDBOptsThe TemplateDBOpts
[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'))

cachierDB.register()

Async: yes

cachierDB.compile()

Async: yes

cachierDB.read()

Async: yes

cachierDB.write()

Async: yes

cachierDB.metadata

cachierDB.statsObject

Returns

  • Object — Combined memory-cache and database-operation statistics.

cachierDB.resetStats()Object

Returns

  • Object — The reset combined statistics.

cachierDB.clearMemory()

Clears in-memory database records and inherited template/render caches without deleting persisted records.

Async: yes

cachierDB.clear([all=true])

Clears templates that may reside in-memory, optionally clears the IndexedDB keys in the cache store(s) and closes any lingering DB connections.

Async: yes

Parameters

NameTypeDefaultDescription
[all=true]BooleantrueWhen true all of the keys in the IndexedDB cache store(s) will be removed

cachierDB.close()

Closes the active database connection and clears in-memory entries without deleting persisted records.

Async: yes

cachierDB.operations

Released under the MIT License.