PersistentStorage is an abstraction for a storage facility that allows you to store values that persists over multiple invocations of your Silverlight application. For example, you can save the user’s login name, and it’s there when they close their browser and come back the next day.
This library is dependent on the great work of Mike Talbot’s Silverlight serializer, without which, arbitrary object storage would still be a dream.
Benefits of Using Persistent Storage
Using this library would benefits you in these ways:
- Easy way to store persistent data over multiple sessions of using your application
- Store data without worrying too much about the complexities of doing so
- Obfuscation and encryption (AES) of data to prevent tampering
Below is some sample code to save a number of collisions, and a player name, to Persistent Storage:
// Sample initialization code
string playerName = "Deenie"; // take it from the UI
PersistentStorage.Store("player name", playerName);
PersistentStorage.Store("number of collisions", 0);
// New from 1.1: store arbitrary objects
PersistentStorage.Store("player", new Player("Ashiq"));
// To retrieve this information later
string playerName = PersistentStorage .Retrieve("player name");
int numCollisions = PersistentStorage.Retrieve("number of collisions");
Player ashiq = PersistentStorage.Retrieve("player"))
As you can tell, there’s no initialization, configuration, or setup required; just call the static functions and you’re ready to go. No type-casting or typing required.
PersistentStorage is an abstraction for persistent storage. Internally, it uses either Silverlight’s IsolatedStorage (for Silverlight apps) if available, or cookies (if IsolatedStorage is disabled).
It provides, for IsolatedStorage facility, hashing (to obfuscate variable names) and encryption (of values via AES); due to limited space (4kb max!), these are not used in the cookies-based version. This might change in the future.
We also use the strategy design pattern; we have a storage provider interface, and different implementations–at this point, an IsolatedStorage-based implementation (the default), and a cookie-based implementation (the backup, if IsolatedStorage is disabled).
For future development, if there’s need, we might add functionality for the following:
- Manage “shared” information (for non-cookie storage) that applications can save and allow other applications to access.
- Create a desktop equivalent (that relies on Serialization) to accomplish the same functionality for desktop applications
- Add a hash digest to every variable stored to verify that the value was not tampered with