![]() |
VOOZH | about |
dotnet add package NeoSmart.Caching.Sqlite --version 9.0.1
NuGet\Install-Package NeoSmart.Caching.Sqlite -Version 9.0.1
<PackageReference Include="NeoSmart.Caching.Sqlite" Version="9.0.1" />
<PackageVersion Include="NeoSmart.Caching.Sqlite" Version="9.0.1" />Directory.Packages.props
<PackageReference Include="NeoSmart.Caching.Sqlite" />Project file
paket add NeoSmart.Caching.Sqlite --version 9.0.1
#r "nuget: NeoSmart.Caching.Sqlite, 9.0.1"
#:package NeoSmart.Caching.Sqlite@9.0.1
#addin nuget:?package=NeoSmart.Caching.Sqlite&version=9.0.1Install as a Cake Addin
#tool nuget:?package=NeoSmart.Caching.Sqlite&version=9.0.1Install as a Cake Tool
SqliteCache is a persistent cache
implementing IDistributedCache for .NET and ASP.NET Core projects.
SqliteCache uses a locally stored SQLite database file (taking advantage of SQLite's battle-tested
safe multi-threaded access features) to replicate persistent caching, allowing developers to mimic
the behavior of staging or production targets without all the overhead or hassle of a traditional
IDistributedCache implementation. You can read more about its design and inspiration in the
official release post on the NeoSmart
blog.
NeoSmart.Caching.Sqlite?The currently available options for caching in ASP.NET Core projects are either all ephemeral
in-memory cache offerings (IMemoryCache and co.) -- aka non-persistent -- or else have a whole
slew of dependencies and requirements that require at the very least administrator privileges and
background services hogging up system resources and needing updates and maintenance to requiring
multiple machines and a persistent network configuration.
NeoSmart.Caching.Sqlite has no dependencies on background services that hog system resources and
need to be updated or maintained (cough cough NCache cough cough)NeoSmart.Caching.Sqlite is fully cross-platform and runs the same on your Windows PC or your
colleagues' Linux, FreeBSD, and macOS workstations (unlike, say, Redis)NeoSmart.Caching.Sqlite doesn't need administrator privileges to install - or even any installation
for that matter (SQL Express LocalDB, this one is aimed at you)NeoSmart.Caching.Sqlite is a fully contained IDistributedCache offering that is installed and
updated alongside the rest of your packages via NuGet, Paket, or whatever other option you're
already using to manage your dependencies.SqliteCache is available via the NuGet, and can be installed in the Package Manager Console as follows:
Install-Package NeoSmart.Caching.Sqlite
If using this in an ASP.NET Core project, you can install NeoSmart.Caching.Sqlite.AspNetCore (also
or instead) to get a convenient helper method for dependency injection (used below):
Install-Package NeoSmart.Caching.Sqlite.AspNetCore
Note: If you install NeoSmart.Caching.Sqlite.AspNetCore you do not need to manually install
NeoSmart.Caching.Sqlite, as it it will be installed automatically/transitively.
Using SqliteCache is straight-forward, and should be extremely familiar for anyone that's configured
an ASP.NET Core application before. Starting by adding a namespace import using NeoSmart.Caching.Sqlite makes things easier as the editor will pull in the correct extension
methods.
If using SqliteCache in an ASP.NET Core project, the SQLite-backed cache should be added as an
IDistributedCache type by adding the following to your ConfigureServices method, by default
located in Startup.cs, after using the correct namespace NeoSmart.Caching.Sqlite:
// using NeoSmart.Caching.Sqlite;
public void ConfigureServices(IServiceCollection services)
{
...
// Note: this *must* come before services.AddMvc() and/or services.AddRazorPages()!
services.AddSqliteCache(options => {
options.CachePath = @"C:\data\bazaar\cache.db";
});
services.AddMvc();
...
}
Afterwards, the SqliteCache instance will be made available to both the framework and the
application via dependency injection, and can be imported and used via either the
IDistributedCache abstract type or the concrete SqliteCache type:
// using Microsoft.Extensions.Caching.Distributed;
public class FooModel(DbContext db, IDistributedCache cache)
{
_db = db;
_cache = cache;
cache.SetString("foo", "bar");
Assert.AreEqual(cache.GetString("foo"), "bar");
Assert.AreEqual(typeof(NeoSmart.Caching.Sqlite.SqliteCache),
cache.GetType());
}
To take advantage of SqliteCache-specific features or functionality that aren't exposed via the
IDistributedCache façade, you'll need to inject SqliteCache into your classes/methods rather than
IDistributedCache. For example, to globally clear the cache after performing some operation:
// using NeoSmart.Caching.Sqlite;
public class BarModel(DbContext db, SqliteCache cache)
{
_db = db;
_cache = cache;
}
public ActionResult OnPostAsync()
{
...
await _db.SomethingDestructiveAsync();
// We need to invalidate all the cache, since it's too hard to
// account for the changes this operation caused for legacy reasons.
await _cache.ClearAsync();
...
}
SqliteCache is developed and maintained by Mahmoud Al-Qudsi of NeoSmart Technologies. The project is provided free to the community under the terms of the MIT open source license.
We are open to pull requests and contributions aimed at the code, documentation, unit tests, or anything else. If you're mulling an extensive contribution, file an issue first to make sure we're all on the same page, otherwise, PR away!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on NeoSmart.Caching.Sqlite:
| Package | Downloads |
|---|---|
|
NeoSmart.Caching.Sqlite.AspNetCore
ASP.NET Core dependency-injection integrations for NeoSmart.Caching.Sqlite |
|
|
Pillsgood.AdventOfCode
Package Description |
Showing the top 1 popular GitHub repositories that depend on NeoSmart.Caching.Sqlite:
| Repository | Stars |
|---|---|
|
Kareadita/Kavita
Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 9.0.1 | 123,229 | 2/19/2025 | |
| 9.0.0 | 10,250 | 11/28/2024 | |
| 9.0.0-preview1 | 231 | 10/26/2024 | |
| 8.0.1 | 19,429 | 2/19/2025 | |
| 8.0.0 | 106,057 | 3/2/2024 | |
| 7.0.1 | 18,736 | 9/19/2023 | |
| 7.0.0 | 3,294 | 9/5/2023 | 7.0.0 is deprecated. |
| 7.0.0-preview1 | 961 | 6/29/2023 | |
| 6.1.0 | 20,935 | 6/29/2023 | |
| 6.1.0-preview1 | 13,817 | 1/30/2023 | |
| 6.0.1 | 49,772 | 1/10/2022 | |
| 6.0.0 | 3,128 | 1/10/2022 | 6.0.0 is deprecated. |
| 5.0.2 | 4,703 | 1/10/2022 | |
| 5.0.1 | 3,023 | 1/10/2022 | 5.0.1 is deprecated. |
| 5.0.0 | 3,030 | 1/10/2022 | 5.0.0 is deprecated. |
| 5.0.0-preview3 | 429 | 11/2/2021 | |
| 5.0.0-preview2 | 464 | 7/31/2021 | |
| 5.0.0-preview1 | 464 | 7/13/2021 | |
| 3.1.1 | 47,370 | 1/18/2020 | |
| 3.1.0 | 3,133 | 1/4/2020 |
Version 7.0:
- SqliteCache no longer depends on SQLitePCLRaw.bundle_green.
ASP.NET users should install companion package NeoSmart.Caching.Sqlite.AspNetCore.
Other .NET Core users will need to install either SQLitePCLRaw.bundle_green and call
`SQLitePCL.Batteries.Init()` before instantiating SqliteCache, or else install the
correct SQLitePCLRaw.provider.xxx version that matches the target platform and call
`SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_whatever())` before using
SqliteCache.
Version 6.1:
- Add methods to clear the cache (SqliteCache.Clear() and SqliteCache.ClearAsync())
- SQLitePCLRaw upgraded to 2.1.4
- Compatible w/ SQLite builds compiled with SQLITE_DSQ=0
Version 6.0:
- Updates all Entity Framework and Microsoft Extension dependencies to v6.x
Version 5.0:
- WAL mode and normal synchronization pragmas are set at startup, dramatically improving performance
- ILogger constructor parameter is now optional
- A separate SqliteConnection is used for each SqlCommand instance, fixing threading issues under UWP
- Makes it possible to inject SqliteCache directly (rather than only as IDistributedCache)
- Adds IAsyncDisposable implementation for .NET Core 3.1 and above
- Adds a bulk insert option to insert many key-value pairs quickly (credit to first-time contributor Elias Baumgartner aka @Rap22tor)
- Fixes an issue w/ incorrect handling of user-specified non-UTC expiration dates (credit to first-time contributor Ravindu Liyanapathirana, aka @ravindUwU)
Version 3.1:
- Added .netcoreapp3.1 target
- Switched to SQLitePCLRaw.bundle_e_sqlite3 (same as .NET Core 3.1 web projects)
- SqliteCache is now a sealed class to prevent dispose problems if derived
- Version number aligns with .NET Core semantic versioning