A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.nativescript.org/core/image-cache below:

ImageCache | NativeScript

ImageCache allows you to cache an image from an HTTP request. You can alternatively use a plugin that auto handles image caching like @triniwiz/nativescript-image-cache-it.

Using ImageCache

For consistency, you should use a single ImageCache instance throughout your app.

ts
import { ImageCache } from '@nativescript/core'

const imageCache = new ImageCache()
Save an image to cache

To retrieve an image from a remote server and cache it, use either the push or enqueue method. These methods cache the android.graphics.Bitmap (Android) or UIImage (iOS) instance.

ts
imageCache.enqueue({
  url: this.url,
  key: 'cat',
  completed(image: android.graphics.Bitmap | UIImage, key) {
    console.log('Successfully retrived and cached the cat image')
  },
  error(key) {
    console.log('cache error')
  },
})

Note

To call the push method instead, just replace enqueue with push

Getting an image from cache

To get an image from the cache, use the get method.

ts
const cachedImage = imageCache.get('cat')
API constructor ts
const imageCache = new ImageCache()

Creates an ImageCache instance.

placeholder ts
imageCache.placeholder = imageSource

The image to be used to notify for a pending download request - e.g. loading indicator.

maxRequests

The maximum number of simultaneous download requests. Defaults to 5

push ts
imageCache.push(request)

Adds a new image to the start of the cache. request is an object with the following members:

enqueue ts
imageCache.enqueue(request)

Adds a new image to the end of the cache. For more details about the request parameter, see the push() method.

get

Gets the image with a given key from the cache, or undefined if it's not in the cache.

remove ts
imageCache.remove(imageKey)

Remove the specified image from the cache.

clear

Clears all the images from the cache.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4