I'm trying to use Aura storage facility to store some graph data on a client side. to create a storage i use:
function getStorage() {
var storageName = "GraphsData";
var storage = $A.storageService.getStorage(storageName);
if (!storage) {
console.log("creating storage...");
storage = $A.storageService.initStorage({
name: storageName, // name
persistent: true, // persistent
secure: true, // secure
maxSize: 1024*1024*10, // maxSize in bytes
defaultExpiration : 60000, // defaultExpiration (seconds)
defaultAutoRefreshInterval: 60000, // defaultAutoRefreshInterval (seconds)
debugLoggingEnabled: true, // debugLoggingEnabled
clearStorageOnInit: false, // clearStorageOnInit
version: "1.0" // version
});
}
console.log("storage: " + storage);
return storage;
}
And it works, i can store some data there by executing:
storage.set("graphData", data);
And retrieve data by:
getGraphData : function() {
var storage = getStorage();
return storage.get("graphData").then( function(data) {
if (data) {
var promise = new Promise(function(resolve, reject) {
resolve(data);
});
return promise;
}
else
{
.....
But after 8-10 seconds, when i try to retrieve data from storage again, storage returns undefined (like the data was removed). But why so fast? i played with different initialization parameters, but it changed nothing.
ok, i found that documentation is misleading (wrong).
by looking into component (thru debug console) i found different properties:
AuraStorage {$adapter$: MemoryAdapter, name: "GraphsData", $maxSize$: 10485760, $expiration$: 10000, $autoRefreshInterval$: 30000…}
$adapter$: MemoryAdapter
$autoRefreshInterval$ : 30000
$debugLogging$ : false
$expiration$ : 10000
$getOperationsInFlight$ : 0
$keyPrefix$ : "1.0:"
$lastSweepTime$ : 1468848393250
$maxSize$ : 10485760
$sweepInterval$ : 300000
$sweepPromise$ : undefined
$sweepingSuspended$ : false
adapter : MemoryAdapter
name : "GraphsData"
version : "1.0"
after setting expiration parameter (instead of defaultExpiration), everything started to work as expected. Now i use
expiration : 600,
for 10 minutes expiration