Newer Version Available
Caching with Storage Service
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.
- 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 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.