ServerStorage: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Line 33: Line 33:


<pre>
<pre>
Rem serverStorage Save Example
Sub Main()
serverStorage.data = "This is Data."
  NameSpace.text = serverStorage.namespace
(run and exit program)
End Sub
Rem serverStorage Retrieve Example
Print serverStorage.data
Rem Test if Private Browsing is turned on
Try
  serverStorage.private = "test"
Catch err
  MsgBox "Please turn Private Browsing off"   
End Try


Rem Some additional samples:
Function Button1_onclick()
serverStorage.setItem("key", value) 'creates serverStorage.key with defined value
  t=SysInfo(10)
serverStorage["key"] = value 'alternative method for above
  For i = 1 To 10
serverStorage.getItem("key") 'calls serverStorage.key...useful to check if it exists
    serverStorage.setItem("item" & i, i)
serverStorage.removeItem("key") 'deletes serverStorage.key
  Next
delete serverStorage.key 'alternative method for above
  MsgBox "Write 10 items into serverStorage(secs): " &  (SysInfo(10)-t)/1000
delete serverStorage["key"] 'another alternative method for above
End Function
serverStorage.clear() 'nuclear deletion of all serverStorage variables in the domain. Use with care.
 
serverStorage[DBRecords.rows.item(0)["ModsType"]] = "alpha"
Function Button2_onclick()
  NSB.Print(False)
  For i=0 To serverStorage.length-1
    key = serverStorage.key(i)
    Print key, serverStorage.getItem(key)
  Next
End Function
 
Function Button3_onclick()
  serverStorage.clear()
End Function
</pre>
</pre>



Revision as of 16:30, 6 November 2014

serverStorage(string | variable)

Description

ServerStorage allows you to save string data 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.

By default, the data is saved into a namespace with the same name as the app's ID. It can be set to any string, even that of another app, making it possible for apps to share data.

ServerStorage is insecure: there is currently no protection against other apps reading or changing the data.

This feature is currently experimental. It only works on apps deployed to nsbapp.com. It will not work locally or on your server at this time. Since the data is on the nsbapp.com test server, do not assume that data you save will be permanently available.

Properties and Methods

clear() Clear all entries in the current namespace.
deleteItem(key) Deletes item key.
getItem(key) Get the item which is saved under key. String.
key(n) Get the nth item in the namespace.
length The number of items in the current namespace.
namespace The group used by all serverStorage methods. Defaults to app ID.
setItem(key, value) Sets item key to value. Creates item if it does not exist.

Example

Sub Main()
  NameSpace.text = serverStorage.namespace
End Sub

Function Button1_onclick()
  t=SysInfo(10)
  For i = 1 To 10
    serverStorage.setItem("item" & i, i)
  Next
  MsgBox "Write 10 items into serverStorage(secs): " &  (SysInfo(10)-t)/1000
End Function

Function Button2_onclick()
  NSB.Print(False)
  For i=0 To serverStorage.length-1
    key = serverStorage.key(i)
    Print key, serverStorage.getItem(key)
  Next
End Function

Function Button3_onclick()
  serverStorage.clear()
End Function

Output

This is Data.

Related Items

LocalStorage, SessionStorage, SQL