Skip to content

SVG framework function: enableCache

This tutorial is part of Iconify SVG Framework functions tutorial.

Function enableCache() enables or toggles caching in localStorage and sessionStorage.

When the SVG framework retrieves new icons from API, icon data is stored in browser storage. Cache makes rendering faster because SVG framework can retrieve icons from cache instead of sending an API query. Unlike API queries, cache is instant.

By default, localStorage is enabled, sessionStorage is disabled.

Usage

The function has the following parameters:

  • storage. Storage to enable.
  • enable, boolean. Optional value. If false, function will disable storage instead of enabling it, behaving like disableCache().

Storage types

The first parameter can be one of the following:

  • "local" for localStorage.
  • "session" for sessionStorage.
  • "all" for both localStorage and sessionStorage.

Examples

js// Enable caching in localStorage
Iconify.enableCache('local');

Another example:

js// Disable all caching
Iconify.enableCache('all', false);

Notes

  • Enabling or disabling the cache will not affect icon data already stored in the cache. Icon data will always be loaded, regardless of setting. The setting affects only storing new icon data retrieved from API.
  • Setting affects only icon data loaded from the Iconify API. Icon data loaded with addIcon() or addCollection() is not cached.
  • When both localStorage and sessionStorage are enabled, icon data is cached only in localStorage.

Released under the Apache 2.0 License.