Newer Version Available

This content describes an older version of this product. View Latest

Caching with Storage Service

The Storage Service provides a powerful, simple-to-use caching infrastructure that enhances the user experience on the client. Client applications can benefit from caching data to reduce response times of pages by storing and accessing data locally rather than requesting data from the server. Caching is especially beneficial for high-performance, mostly connected applications operating over high latency connections, such as 3G networks.

The advantage of using the Storage Service instead of other caching infrastructures, such as Apple local storage for iOS devices, is that the Storage Service offers several types of storage through adapters. Storage can be persistent and secure. With persistent storage, cached data is preserved between user sessions in the browser. With secure storage, cached data is encrypted.

Storage Adapter Name Persistent Secure
SmartStore true true
IndexedDB true false
MemoryAdapter false true
SmartStore
(Persistent and secure) Provides a caching service that is only available for apps built with the Salesforce Mobile SDK. The Salesforce Mobile SDK enables developing mobile applications that integrate with Salesforce. You can use SmartStore with these mobile applications for caching data.
IndexedDB
(Persistent but not secure) Provides access to an API for client-side storage and search of structured data. For more information, see the Indexed Database API.
MemoryAdapter
(Not persistent but secure) Provides access to the JavaScript main memory space for caching data. The stored cache persists only per browser page. Browsing to a new page resets the cache.

The Storage Service selects a storage adapter on your behalf that matches the persistent and secure options you specify when initializing the service. For example, if you request a persistent and insecure storage service, the Storage Service returns the IndexedDB storage.

There are two types of storage:
  • Custom named storage: Storage that you control by adding and retrieving items to and from storage.
  • Framework-provided actions storage: Storage for server-side actions that enables caching action response values.

When you initialize storage, you can set certain options, such as the maximum cache size and the default expiration time. The storage name is required and must be unique.

The storage name can be any name except for “actions”, which is reserved for the server action storage that the framework uses.

Note

The expiration time for an item in storage specifies the duration after which an item should be replaced with a fresh copy. The refresh interval takes effect only if the item hasn’t expired yet and applies to the actions storage only. In that case, if the refresh interval for an item has passed, the item gets refreshed after the same action is called. If stored items have reached their expiration times or have exceeded their refresh intervals, they’re replaced only after a call is made to access them and if the client is online.