the uncached storage behind the cache
Optional
cache: Cachethe cache to use; if undefined an in-memory cache will be used; IMPORTANT: The default in-memory cache does not with multi-process or multi-machine setups!
Protected
Optional
cachethe cache to use; if undefined an in-memory cache will be used; IMPORTANT: The default in-memory cache does not with multi-process or multi-machine setups!
Protected
storagethe uncached storage behind the cache
Adds a library file to a library. The library metadata must have been installed with addLibrary(...) first. Throws an error if something unexpected happens. In this case the method calling addFile(...) will clean up the partly installed library.
The library that is being installed
Filename of the file to add, relative to the library root
The stream containing the file content
true if successful
Adds the metadata of the library to the repository and assigns a new id to the installed library. This dea is used later when the library must be referenced somewhere. Throws errors if something goes wrong.
The library metadata object (= content of library.json)
True if the library can only be used be users allowed to install restricted libraries.
The newly created library object to use when adding library files with addFile(...)
Invalidates the whole cache.
Removes all files of a library. Doesn't delete the library metadata. (Used when updating libraries.)
the library whose files should be deleted
Removes the library and all its files from the repository. Throws errors if something went wrong.
The library to remove.
Check if the library contains a file.
The library to check
true if file exists in library, false otherwise
Not cached as the function will be called only very rarely.
Not cached as the function will be called only very rarely.
Returns a information about a library file. Throws an exception if the file does not exist.
library
the relative path inside the library
the file stats
We don't cache file streams, as this doesn't make much sense. A better way to improve performance of files requested individually by the client is to serve them statically, i.e. directly via Express or by offloading them to S3 storage or a CDN.
Returns all installed libraries or the installed libraries that have the machine name.
Optional
machineName: string(optional) only return libraries that have this machine name
the libraries installed
Gets a list of installed language files for the library.
The library to get the languages for
The list of JSON files in the language folder (without the extension .json)
Gets the information about an installed library
the library
the metadata and information about the locally installed library
Checks if a library is installed.
the library to check
true if the library is installed
Optional
listReturns a list of library addons that are installed in the system. Addons are libraries that have the property 'addTo' in their metadata. ILibraryStorage implementation CAN but NEED NOT implement the method. If it is not implemented, addons won't be available in the system.
Gets a list of all library files that exist for this library.
all files that exist for the library
Updates the additional metadata properties that is added to the stored libraries. This metadata can be used to customize behavior like restricting libraries to specific users.
Implementations should avoid updating the metadata if the additional metadata if nothing has changed.
the library for which the metadata should be updated
the metadata to update
true if the additionalMetadata object contained real changes and if they were successfully saved; false if there were not changes. Throws an error if saving was not possible.
Updates the library metadata. This is necessary when updating to a new patch version. After this clearFiles(...) is called by the LibraryManager to remove all old files. The next step is to add the patched files with addFile(...).
the new library metadata
The updated library object
A wrapper around an actual library storage which adds caching and also handles cache invalidation for you. You can use this method as a drop-in replacement for other library storages.
It uses the NPM package
cache-manager
to abstract the caching, so you can pass in any of the store engines supported by it (e.g. redis, mongodb, fs, memcached). See the documentation page ofcache-manager
for more details.Note: If you construct
CachedLibraryStorage
without a cache, it will default to an in-memory cache that is not suitable for multi-process or multi-machine setups!