@resee-movies/utilities - v0.8.0
    Preparing search index...

    Class TmdbImageCache

    The TmdbImageCache provides a mechanism to keep track of image URLs that have been downloaded from TMDB at specific resolutions. This allows for a few tricks to be performed, such as:

    • If already loaded, a lower-resolution image can be immediately displayed, while its higher-resolution version downloads in the background.
    • If a higher-resolution image is already loaded, the loading of a lower resolution image can be skipped entirely.

    Instances of this class can be made for whatever wacky purposes you can think up, but it is recommended to use the getTmdbImageCache utility method, which will always return the same singleton instance.

    Index

    Constructors

    Properties

    cache: Map<string, number[]> = ...

    Methods

    • Add the provided imageId at the given resolution to the cache, indicating that it has already been downloaded and is available for use.

      Parameters

      • imageId: string
      • requestedSize: number

      Returns void

    • Checks the cache Map for the existence of the requested image. If the requested image has already been loaded at the desired resolution or higher, then this method returns a status of "available", otherwise a status of "required" is returned.

      Parameters

      • imageId: string
      • requestedSize: number

      Returns undefined | { imageId: string; numericSize: number; status: string }

    • Retrieve a full URL for a TMDB image asset. This method will return a string if a suitable image asset already exists for the request, or if the method is being called from a server context where the Image class is not available. Otherwise, a TmdbImageCacheResult promise will be returned, which may or may not have its placeholder property set. If set, this can be used while the promise itself is pending.

      Parameters

      • src: string
      • Optionalsize: string | number

      Returns string | TmdbImageCacheResult

    • Extracts the TMDB image ID, and requested resolution, from the provided arguments.

      Parameters

      • src: string
      • Optionalsize: string | number

      Returns { imageId: string; numericSize: number }