H5P NodeJS Library
    Preparing search index...

    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 of cache-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!

    Implements

    Index

    Constructors

    Properties

    cache?: Cache

    the 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!

    the uncached storage behind the cache

    Methods

    • 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.

      Parameters

      • library: ILibraryName

        The library that is being installed

      • filename: string

        Filename of the file to add, relative to the library root

      • readStream: Readable

        The stream containing the file content

      Returns Promise<boolean>

      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.

      Parameters

      • libraryData: ILibraryMetadata

        The library metadata object (= content of library.json)

      • restricted: boolean

        True if the library can only be used be users allowed to install restricted libraries.

      Returns Promise<IInstalledLibrary>

      The newly created library object to use when adding library files with addFile(...)

    • 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.

      Parameters

      Returns Promise<boolean>

      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.