No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Using Storage Service
After you've initialized your custom storage, you can add and retrieve items from your storage. To do so, use the JavaScript put and get API of AuraStorage.
This example shows how to use the storage object returned by the previous example to store items. The call to put takes a key that is used to uniquely identify the stored item.
1swfobject.registerObject("clippy.codeblock-0", "9");var value1 = 67;
2storage.put("score", value1);
3storage.put("name", "joe smith");You can retrieve stored items by using the get method. The parameters of the get method are the key of the value to retrieve and a callback function. The callback function is called asynchronously and has the item that was fetched from the storage as its parameter.
1swfobject.registerObject("clippy.codeblock-1", "9");storage.get("score", function(item) { var myRetrievedScore = item; });
2storage.get("name", function(item) { console.log(item); });You can obtain any initialized named storage by calling getStorage() and by passing it the storage name. For example:
1swfobject.registerObject("clippy.codeblock-2", "9");var storage = $A.storageService.getStorage("MyStorage");There are other methods you can call on the storage object. For a detailed description of the JavaScript API for AuraStorageService, see AuraStorageService and for AuraStorage, see AuraStorage.
For example, you can get the current cache size and clear the storage, as follows.
1swfobject.registerObject("clippy.codeblock-3", "9");// Get cache size
2var size = $A.storageService.getStorage("MyStorage").getSize();
3// Clear the cache
4$A.storageService.getStorage("MyStorage").clear();