@ndcode/zip_cache v0.1.0
Build Cache wrapper for zipfiles
An NDCODE project.
Overview
The zip_cache package exports a single constructor
ZipCache(diag)
which must be called with the new operator. The resulting cache object stores
the decompressed contents of zipfiles loaded from disk.
See the build_cache and yauzl packages for more information. The ZipCache
object is essentially a wrapper object which routes the request between the
build_cache package and the streaming yauzl zipfile-reading API, to ensure
that the zipfile contents are retrieved from either RAM or disk as required.
Calling API
Suppose one has a ZipCache instance named zc. It behaves somewhat like an
ES6 Map object, except that it only has the zc.get() function, because new
objects are added to the cache by attempting to get them.
The interface for the ZipCache-provided instance function zc.get() is:
await zc.get(key) — retrieves the object stored under key, where
key is the on-disk pathname to a zipfile. A dictionary mapping String to
Buffer objects is returned, where the String is the absolute pathname of a
file within the zipfile (always beginning with /), and the Buffer is the
binary contents of the file. This dictionary is then cached for future use.
Before returning the cached dictionary, the existence and modification time of
the zipfile on disk is checked to make sure that the cache is up-to-date.
Otherwise, if the file doesn't exist an ENOENT exception is thrown, or if the
file exists it is scanned and decompressed and the cache updated for next time.
About diagnostics
The diag argument to the constructor is a bool, which if true causes
messages to be printed via console.log() for all activities except for the
common case of retrieval when the object is already up-to-date. A diag value
of undefined is treated as false, thus it can be omitted in the usual case.
To be implemented
It is intended that we will shortly add a timer function (or possibly just a
function that the user should call periodically) to flush built templates from
the cache after a stale time. There is otherwise no way to delete an object
from the cache, except by first deleting it on disk, then trying to get it.
GIT repository
The development version can be cloned, downloaded, or browsed with gitweb at:
https://git.ndcode.org/public/zip_cache.git
License
All of our NPM packages are MIT licensed, please see LICENSE in the repository.
Contributions
The caching system is under active development (and is part of a larger project that is also under development) and thus the API is tentative. Please go ahead and incorporate the system into your project, or try out our example webserver built on the system, subject to the caution that the API could change. Please send us your experience and feedback, and let us know of improvements you make.
Contact: Nick Downing nick@ndcode.org
7 years ago