LocalStorage 2.0.0-beta-2

This is a prerelease version of LocalStorage.
There is a newer version of this package available.
See the version list below for details.
dotnet add package LocalStorage --version 2.0.0-beta-2                
NuGet\Install-Package LocalStorage -Version 2.0.0-beta-2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LocalStorage" Version="2.0.0-beta-2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LocalStorage --version 2.0.0-beta-2                
#r "nuget: LocalStorage, 2.0.0-beta-2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LocalStorage as a Cake Addin
#addin nuget:?package=LocalStorage&version=2.0.0-beta-2&prerelease

// Install LocalStorage as a Cake Tool
#tool nuget:?package=LocalStorage&version=2.0.0-beta-2&prerelease                

LocalStorage for .NET

What is LocalStorage?

LocalStorage is a simple utility that solves a common problem pragmatically - storing and accessing objects quickly in a .NET app. It is designed with a specific vision in mind: provide a simple solution for persisting objects, even between sessions, that is unobtrusive and requires zero configuration.

Getting Started

First, you might want to dive into the examples in this document. Want more, have a look at the tests.

Once you're game, simply add it to your project through NuGet.

NuGet Package Manager:

$ Install-Package LocalStorage

NuGet CLI:

$ nuget install LocalStorage

If you've got an issue...

... grab a tissue. No, seriously; don't hesitate to post an issue, or send me a message at @jhanssens.

LocalStorage is Copyright © 2016-2017 Juliën Hanssens under the MIT license.

Documentation

Examples

The tests are some pretty good examples to get familiar with the lib. But here is the short summary on the LocalStorage API.

Basic CRUD operations
Initialize
// initialize, with default settings
var storage = new LocalStorage();

// ... or initialize with a custom configuration 
var config = new LocalStorageConfiguration() { 
	// see the section "Configuration" further on
};

var storage = new LocalStorage(config);
Store()
// store any object, or collection providing only a 'key'
var key = "whatever";
var value = "...";

storage.Store(key, value);
Get()
// fetch any object - as object
storage.Get(key);

// if you know the type, simply provide it as a generic parameter
storage.Get<Animal>(key);
Query()
// fetch a strong-typed collection
storage.Query<Animal>(key);

// you can also provide a strong-typed where-clause in one go
storage.Query<Animal>(key, x => x.Name == "Sloth");
Other operations
Count

Returns the amount of items currently in the LocalStorage container.

Clear()

Clears the in-memory contents of the LocalStorage, but leaves any persisted state on disk intact.

Destroy()

Deletes the persisted file on disk, if it exists, but keeps the in-memory data intact.

Load()

Loads the persisted state from disk into memory, overriding the current memory instance. If the file does not exist, it simply does nothing.
By default, this is done automatically at initialization and can be overriden by disabling AutoLoad in the configuration.

Persist()

Persists the in-memory store to disk.
Note that by default, this is also done automatically when the LocalStorage disposes properly. This can be changed by disabling AutoSave in the configuration.

Configuration

Here is a sample configuration with all configurable members (and their default values assigned):

  • AutoLoad (bool)
    Indicates if LocalStorage should automatically load previously persisted state from disk, when it is initialized (defaults to true).

  • AutoSave (bool)
    Indicates if LocalStorage should automatically persist the latest state to disk, on dispose (defaults to true).

  • Filename (string)
    Filename for the persisted state on disk (defaults to ".localstorage").

  • EnableEncryption

Security is an important feature. LocalStorage has support for encrypting the data, both in-memory as well as persisted on disk.

You only need to define a custom configuration indication that encryption should be enabled:

// setup a configuration with encryption enabled (defaults to 'false')
// note that adding EncryptionSalt is optional, but recommended
var config = new LocalStorageConfiguration() {
	EnableEncryption = true,
	EncryptionSalt = "(optional) add your own random salt string"
};

// initialize LocalStorage with a password of your choice
var encryptedStorage = new LocalStorage(config, "password");

All write operations are first encrypted with AES, before they are persisted in-memory. In case of disk persistance, the encrypted value is respected. Although enabling encryption increases security, it does add a slight overhead to the Get/Store operations, in terms of performance.

By design, only the values are encrypted and not the keys.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on LocalStorage:

Package Downloads
OnePoint.Flow

OnePoint Global Data FLow Library

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on LocalStorage:

Repository Stars
trevoirwilliams/HR.LeaveManagement.CleanArchitecture-dotnet5
Educational Project to demonstrate MediatR, CQRS & Onion/Clean Architecture in ASP.NET Core
Version Downloads Last updated
2.1.0 111,752 2/18/2021
2.0.0 72,240 3/19/2019
2.0.0-beta-2 2,834 8/14/2018
2.0.0-beta 845 8/13/2018
1.1.0 13,156 2/25/2017
1.0.0 1,483 2/11/2017
1.0.0-preview 1,150 1/28/2017

See the releases page on GitHub for release notes:
https://github.com/hanssens/localstorage-for-dotnet/releases