tp.Local and tp.Session

tp.Local and tp.Session are small wrappers around the browser Web Storage API. tp.Local uses localStorage, which persists for the origin. tp.Session uses sessionStorage, which is kept for the current browser page session.

Both classes inherit from tp.BrowserStorage and provide the same static methods: Available, Get(), Set(), Remove(), GetObject(), SetObject(), and Clear(). This demo uses only demo-prefixed keys and removes only those keys, so it does not clear unrelated browser storage.

String values

Set() stores string values and Get() reads them back. When a key is missing, Get() returns the supplied default value.

Object values

SetObject() serializes with JSON and GetObject() parses the stored JSON text. Invalid or missing JSON returns the default value.

Availability and cleanup

Available is false when the browser storage API is blocked or not available. Remove() deletes one key. Clear() clears all keys for the origin, so this demo does not call it.

Demo keys

The demo uses these keys only: tp.demo.storage.text and tp.demo.storage.object.