LocalStorage for .NET

It happened once too often. For the last time I wrote another helper class that serialized<>deserialized some stuff to the filesystem, just so it could be restored in a new debug session. “What a bless localStorage for Javascript is…”, I thought to myself. And with that thought, I started to work on LocalStorage for .NET.

LocalStorage is an extremely lightweight, dependency-less library with a simple concept: allow any .NET object to be stored in an in-memory store – and allow it to be persisted to filesystem. It serves the purpose of filling the gap where most in-memory caches, or key/value stores, are too complex or require either an install or some sort of tedious configuration before you can start coding.

LocalStorage for .NET is inspired by – but totally unrelated to – Javascript’s localStorage; a temporary caching lib for low-demanding data needs.


If you want to get started fast, simply install the library through NuGet:

$ Install-Package LocalStorage

I’ve made some effort to describe the how-and-what in detail in the README of the project, along with a bunch of examples, but let me oversimplify its use with the following sample:

// initialize a new instance
// (see the README for more configurable options)
using (var storage = new LocalStorage()) 
    // store any object
    var weapon = new Weapon("Lightsaber");
    storage.Save("weapon", weapon);

    // ... and retrieve the object back
    var target = storage.Get<Weapon>("weapon");

    // or store + get a collection
    var villains = new string[] { "Kylo Ren", "Saruman", "Draco Malfoy" };
    storage.Save("villains", villains);

    // ... and get it back as an IEnumerable
    var target = storage.Query<string>("villains");

    // finally, persist the stored objects to disk (.localstorage file)

Again, take a look at the GitHub repo for more in-depth information:

LocalStorage for .NET: it’s dead simple. It has no dependencies. It’s lightweight. And it’s got a memorable name, so hopefully you’ll consider giving it a go yourself someday.