ServerStorage
serverStorage.clear(callback)
serverStorage.getItem(key, callback)
serverStorage.getAllItems(key, callback)
serverStorage.removeItem(key, callback)
serverStorage.setItem(key, value, callback)
Description
ServerStorage allows you to save data in key, value pairs on the server so it is available next time you run the program. An entry can be created by assigning to serverStorage.setItem(variableName, value), where variableName is chosen by you. Data is retrieved a similar way.
value can be a string, number, array or object. There is no size limit on value, other than it be reasonable.
This feature is only available if your app is hosted on Volt. If your app does not have a live internet connection, the request will time out and an error message will be passed to callback.
Since the calls access information on a server, they are asynchronous (so your app does not look up while the call is being processed). When the call is complete, the function named in callback is called in your app. It passes two parameters: (error, data). If the call is successful, error is empty and your results are in data. If the call is unsuccessful, error is not empty and the error message is in data.message.
serverStorage is an alias for $volt.user.storage.
Properties and Methods
clear(callback) | Clear all entries for the app. |
removeItem(key, callback) | Deletes item key. |
getItem(key, callback) | Get the item which is saved under key. String. |
getAllItems(callback) | Gets all the items for the app, as an array. Each element is a key,value pair. |
setItem(key, value, callback) | Sets item key to value. Creates item if it does not exist. |
Example - BASIC
Function butClear_onclick() serverStorage.clear(done) End Function Function butGetAllItems_onclick() serverStorage.getAllItems(getAllItemsCallback) End Function Function butGetItem_onclick() serverStorage.getItem("SimpleString", getItemCallback) End Function Function butRemoveItem_onclick() serverStorage.removeItem("SimpleString", done) End Function Function butSetItem_onclick() serverStorage.setItem("SimpleString", "ABCD", done) serverStorage.setItem("Number", 123, done) serverStorage.setItem("Array", [1, 2, 3, 4], done) serverStorage.setItem("Object", {firstName: "Eric", lastName: "Cartman"}, done) End Function Function done(error, data) If error Then If data = undefined Then data = {message: "Network Error"} MsgBox data.message Else console.log("success") End If End Function Function getAllItemsCallback(error, data) If error Then If data = undefined Then data = {message: "Network Error"} MsgBox data.message Else Print False For Each key in data console.log(key, data[key]) k = [key, key][0] Print k & ": " & data[key].toString() Next End If End Function Function getItemCallback(error, data) If error Then If data = undefined Then data = {message: "Network Error"} MsgBox data.message Else MsgBox data End If End Function
Example - JavaScript
function Main() { NameSpace.text = serverStorage.namespace; } Button1.onclick = function() { t=SysInfo(10); for (i = 1; i <= 10; i ++) { serverStorage.setItem("item" + i, i); } alert("Write 10 items into serverStorage(secs): " + (SysInfo(10)-t)/1000); } Button2.onclick = function() { NSB.Print(False); for (i=0; i <= serverStorage.length-1; i++) { key = serverStorage.key(i); NSB.Print((key+ " " + serverStorage.getItem(key)) + "<br>"); } } Button3.onclick = function() { serverStorage.clear(); }
Output
(see serverStorage sample)