{"id":21408549,"url":"https://github.com/hanssens/localstorage","last_synced_at":"2026-01-02T00:20:43.513Z","repository":{"id":54417111,"uuid":"80200775","full_name":"hanssens/localstorage","owner":"hanssens","description":"LocalStorage for .NET - A simple and lightweight tool for persisting data in dotnet (core) apps.","archived":false,"fork":false,"pushed_at":"2022-12-08T08:56:57.000Z","size":81,"stargazers_count":75,"open_issues_count":19,"forks_count":17,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-09T17:44:32.629Z","etag":null,"topics":["caching","dotnet-core","storage-api"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hanssens.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-27T11:03:41.000Z","updated_at":"2024-10-26T13:24:00.000Z","dependencies_parsed_at":"2022-08-13T15:00:50.811Z","dependency_job_id":null,"html_url":"https://github.com/hanssens/localstorage","commit_stats":null,"previous_names":["hanssens/localstorage-for-dotnet"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanssens%2Flocalstorage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanssens%2Flocalstorage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanssens%2Flocalstorage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hanssens%2Flocalstorage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hanssens","download_url":"https://codeload.github.com/hanssens/localstorage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225934413,"owners_count":17547740,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caching","dotnet-core","storage-api"],"created_at":"2024-11-22T17:17:04.011Z","updated_at":"2026-01-02T00:20:43.504Z","avatar_url":"https://github.com/hanssens.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LocalStorage for .NET\n\n## What is LocalStorage?\n\nLocalStorage 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**.\n\n#### What is it NOT?\nNote that this library has absolutely nothing to do with [Window.localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) as you know it from web browsers and JavaScript. You cannot, and you arguably should not even want to, read/write data in the Window.localStorage browser space from outside the browser itself. \n\n## Getting Started\n\n### Installing\nFirst, you might want to dive into the [examples in this document](#examples). Want more, have a look [at the tests](https://github.com/hanssens/localstorage-for-dotnet/tree/master/LocalStorage.Tests). \n\nOnce you're game, simply add it to your project [through NuGet](https://www.nuget.org/packages/LocalStorage).\n\nNuGet Package Manager: \n\n    $ Install-Package LocalStorage\n\nNuGet CLI:\n\n    $ nuget install LocalStorage\n\n### Prerequisites\nThe LocalStorage library is built on **netstandard2.0**. This means it's compatible with .NET Core 2.x and up and traditional .NET 4.6.1 and higher. See the Microsoft [docs on .NET Standard compatibility](https://docs.microsoft.com/en-us/dotnet/standard/net-standard#net-platforms-support). \n\nFor traditional .NET 4.6.1+, you also need to have a more recent version of NuGet installed (NuGet v3.6 and up), which comes out-of-the-box with the latest updated versions of Visual Studio 2017 and [JetBrains Rider](https://www.jetbrains.com/rider/).\n\n## If you've got an issue...\n\n... [grab a tissue](https://www.youtube.com/watch?v=UmnN3eVMWgA). No, seriously; don't hesitate to [post an issue](https://github.com/hanssens/localstorage-for-dotnet/issues), or send me a message at [@jhanssens](https://twitter.com/jhanssens).\n\nLocalStorage is Copyright \u0026copy; 2016-2017 [Juliën Hanssens](https://hanssens.com) under the [MIT license](LICENSE.txt).\n\n## Documentation\n\n### Examples\n\nThe tests are some pretty good examples to get familiar with the lib. But here is the short summary on the LocalStorage API.\n\n#### Basic CRUD operations\n\n##### Initialize\n\n\t// initialize, with default settings\n\tvar storage = new LocalStorage();\n\n\t// ... or initialize with a custom configuration \n\tvar config = new LocalStorageConfiguration() { \n\t\t// see the section \"Configuration\" further on\n\t};\n    \n\tvar storage = new LocalStorage(config);\n\n##### Store()\n\n\t// store any object, or collection providing only a 'key'\n\tvar key = \"whatever\";\n\tvar value = \"...\";\n\n\tstorage.Store(key, value);\n\n##### Get()\n\n\t// fetch any object - as object\n\tstorage.Get(key);\n\n\t// if you know the type, simply provide it as a generic parameter\n\tstorage.Get\u003cAnimal\u003e(key);\n\n##### Query()\n\n\t// fetch a strong-typed collection\n\tstorage.Query\u003cAnimal\u003e(key);\n\n\t// you can also provide a strong-typed where-clause in one go\n\tstorage.Query\u003cAnimal\u003e(key, x =\u003e x.Name == \"Sloth\");\n\n#### Other operations\n\n##### Count\nReturns the amount of items currently in the LocalStorage container.\n\n##### Clear()\nClears the in-memory contents of the LocalStorage, but leaves any persisted state on disk intact.\n\n##### Destroy()\nDeletes the persisted file on disk, if it exists, but keeps the in-memory data intact.\n\n##### Load()\nLoads the persisted state from disk into memory, overriding the current memory instance. If the file does not exist, it simply does nothing.  \nBy default, this is done automatically at initialization and can be overriden by disabling `AutoLoad` in the configuration.\n\n##### Persist()\nPersists the in-memory store to disk.  \nNote that by default, this is also done automatically when the LocalStorage disposes properly. This can be changed by disabling `AutoSave` in the configuration.\n\n### Configuration\n\nHere is a sample configuration with all configurable members (and their default values assigned):\n\n* **AutoLoad** (bool)  \n  Indicates if LocalStorage should automatically load previously persisted state from disk, when it is initialized (defaults to true).\n  \n* **AutoSave** (bool)  \n  Indicates if LocalStorage should automatically persist the latest state to disk, on dispose (defaults to true).\n  \n* **Filename** (string)  \n  Filename for the persisted state on disk (defaults to \".localstorage\").\n\n* **EnableEncryption**  \n\nSecurity is an important feature. LocalStorage has support for encrypting the data, both in-memory as well as persisted on disk. \n\nYou only need to define a custom configuration indication that encryption should be enabled:\n\n\t// setup a configuration with encryption enabled (defaults to 'false')\n\t// note that adding EncryptionSalt is optional, but recommended\n\tvar config = new LocalStorageConfiguration() {\n\t\tEnableEncryption = true,\n\t\tEncryptionSalt = \"(optional) add your own random salt string\"\n\t};\n\n\t// initialize LocalStorage with a password of your choice\n\tvar encryptedStorage = new LocalStorage(config, \"password\");\n\nAll 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.\n\nBy design, only the values are encrypted and not the keys. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanssens%2Flocalstorage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhanssens%2Flocalstorage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanssens%2Flocalstorage/lists"}