Baubit.Caching.LiteDB
2026.2.2-prerelease
See the version list below for details.
dotnet add package Baubit.Caching.LiteDB --version 2026.2.2-prerelease
NuGet\Install-Package Baubit.Caching.LiteDB -Version 2026.2.2-prerelease
<PackageReference Include="Baubit.Caching.LiteDB" Version="2026.2.2-prerelease" />
<PackageVersion Include="Baubit.Caching.LiteDB" Version="2026.2.2-prerelease" />
<PackageReference Include="Baubit.Caching.LiteDB" />
paket add Baubit.Caching.LiteDB --version 2026.2.2-prerelease
#r "nuget: Baubit.Caching.LiteDB, 2026.2.2-prerelease"
#:package Baubit.Caching.LiteDB@2026.2.2-prerelease
#addin nuget:?package=Baubit.Caching.LiteDB&version=2026.2.2-prerelease&prerelease
#tool nuget:?package=Baubit.Caching.LiteDB&version=2026.2.2-prerelease&prerelease
Baubit.Caching.LiteDB
DI Extension: Baubit.Caching.LiteDB.DI
Distributed cache samples: Samples
LiteDB-backed L2 store implementation for Baubit.Caching with support for custom ID types.
Installation
dotnet add package Baubit.Caching.LiteDB
Features
- Generic ID Support: Use
long,int,Guid, or any value type implementingIComparable<TId>andIEquatable<TId> - Performance Optimized: Numeric IDs (long/int) deliver better performance than Guid - less memory, better cache locality
- Persistent Storage: File-based LiteDB storage for durable caching
- Automatic ID Generation: Built-in GuidV7 generation for
StoreGuid<TValue>(backward compatible) - Resumable Enumeration: Resume async enumeration sessions across application restarts with configurable persistence
- Thread-Safe: All public APIs are thread-safe
- Capacity Management: Support for bounded and unbounded stores
Backward Compatibility
The StoreGuid<TValue>, StoreLong<TValue>, and StoreInt<TValue> classes were added to maintain backward compatibility with code written against Baubit.Caching v2025.52+. These classes provide concrete implementations that handle ID generation internally, simplifying usage for common scenarios while the abstract Store<TId, TValue> base class enables custom ID type implementations.
Performance
Benchmarks show numeric IDs (long, int) deliver better performance than Guid:
| Operation (ops/sec) | GuidV7 | Long | Long advantage |
|---|---|---|---|
| GetFirstOrDefault | 14.9M–15.5M | 19.6M–22.8M | +26–53% |
| GetEntryOrDefault | 81.1k–81.5k | 82.7k–110.0k | +1–36% |
| GetNextOrDefault | 76.7k–85.3k | 93.9k–95.9k | +10–25% |
| Update | 21.8k–25.6k | 22.4k–30.5k | +3–19% |
| Add | 12.6k–12.8k | 17.0k–19.0k | +35–49% |
| Mixed (50% read / 50% write) | 9.4k–10.3k | 13.6k–14.3k | +32–53% |
| Mixed (80% read / 20% write) | 7.0k–7.3k | 9.1k–9.5k | +24–36% |
| Memory (ID size only) | 16 bytes | 8 bytes | 50% less |
Long IDs are faster due to:
- Smaller key size (8 bytes vs 16) improves cache locality and reduces index overhead
- Faster comparisons and hashing for numeric keys
- Especially noticeable on write-heavy and mixed workloads
Run benchmarks locally:
dotnet run -c Release --project Baubit.Caching.LiteDB.Benchmark
See Baubit.Caching.LiteDB.Benchmark/Results.md for detailed benchmarks.
Usage
Store with Custom ID Types
using Baubit.Caching.LiteDB;
using Microsoft.Extensions.Logging;
// Store with long IDs - recommended for best performance
var storeLong = new StoreLong<string>(
"cache.db",
"myCollection",
loggerFactory);
storeLong.Add(1L, "value", out var entry);
storeLong.GetValueOrDefault(1L, out var value);
// Store with int IDs
var storeInt = new StoreInt<string>(
"cache.db",
"intCollection",
loggerFactory);
storeInt.Add(42, "value", out var entry);
// Store with Guid IDs - uses automatic GuidV7 generation
var storeGuid = new StoreGuid<string>(
"cache.db",
"guidCollection",
loggerFactory);
// Auto-generated ID
storeGuid.Add("value", out var entry1);
// Or provide explicit Guid
storeGuid.Add(Guid.NewGuid(), "value", out var entry2);
Resumable Enumeration
Enumeration sessions can be persisted to LiteDB and resumed after application restarts:
using Baubit.Caching.LiteDB;
using LiteDB;
using Microsoft.Extensions.Logging;
// Create database shared between store and enumerator factory
using var database = new LiteDatabase("cache.db");
var store = new StoreGuid<string>(database, "myCollection", loggerFactory);
// Configure resumable enumeration
var config = new Baubit.Caching.LiteDB.Configuration
{
ResumeSession = true,
PersistPositionEveryXMoves = 10, // Persist every 10 moves (0 = disabled)
PersistPositionBeforeMove = true // Persist before move (crash recovery)
};
var factory = new CacheAsyncEnumeratorFactory<Guid, string>(database, config);
var cache = new OrderedCache<Guid, string>(store, factory, loggerFactory);
// First enumeration session
var enumerator = factory.CreateEnumerator(cache, _ => {}, "my-session", CancellationToken.None);
await enumerator.MoveNextAsync(); // First entry
await enumerator.MoveNextAsync(); // Second entry
await enumerator.DisposeAsync(); // Position persisted
// Resume from saved position (even after application restart)
var enumerator2 = factory.CreateEnumerator(cache, _ => {}, "my-session", CancellationToken.None);
await enumerator2.MoveNextAsync(); // Continues from third entry
Configuration Options:
ResumeSession- Enable/disable session resumption (default: false)PersistPositionEveryXMoves- Persist every X moves, 0 to disable (default: 0)PersistPositionBeforeMove- Persist before move for crash recovery, false for after move (default: true)
Creating the Store
using Baubit.Caching.LiteDB;
using Microsoft.Extensions.Logging;
// Uncapped store with automatic Guid generation
var store = new StoreGuid<string>(
"cache.db",
"myCollection",
loggerFactory);
// Capped store
var cappedStore = new StoreGuid<string>(
"cache.db",
"myCollection",
minCap: 100,
maxCap: 1000,
loggerFactory);
// Store with custom ID type - long
var longStore = new StoreLong<string>(
"cache.db",
"longCollection",
loggerFactory);
// Use with existing LiteDatabase instance
using var db = new LiteDatabase("cache.db");
var sharedStore = new StoreGuid<string>(db, "myCollection", loggerFactory);
Basic Store Operations
// Store with long IDs - explicit ID required
var storeLong = new StoreLong<string>("cache.db", "col", loggerFactory);
storeLong.Add(1L, "value", out var entry);
storeLong.GetValueOrDefault(1L, out var value);
storeLong.Update(1L, "new value");
storeLong.Remove(1L, out var removed);
storeLong.GetCount(out var count);
// Store with Guid IDs - auto-generates IDs
var storeGuid = new StoreGuid<string>("cache.db", "guidCol", loggerFactory);
storeGuid.Add("value", out var entryGuid); // ID auto-generated
storeGuid.GetCount(out var countGuid);
License
MIT
| Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.0
- Baubit.Caching (>= 2026.2.2-prerelease)
- LiteDB (>= 5.0.21)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Baubit.Caching.LiteDB:
| Package | Downloads |
|---|---|
|
Baubit.Caching.LiteDB.DI
Dependency injection module for Baubit.Caching.LiteDB. Registers IOrderedCache with LiteDB-backed L2 storage in your DI container. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.22.1 | 116 | 5/29/2026 |
| 2026.19.1 | 196 | 5/4/2026 |
| 2026.18.1 | 177 | 4/27/2026 |
| 2026.4.1 | 196 | 1/25/2026 |
| 2026.2.3-prerelease | 173 | 1/10/2026 |
| 2026.2.2-prerelease | 116 | 1/10/2026 |
| 2026.2.1-prerelease | 111 | 1/10/2026 |
| 2026.1.1 | 219 | 12/31/2025 |
| 2026.1.1-prerelease | 112 | 12/31/2025 |
| 2025.52.1-prerelease | 206 | 12/25/2025 |
| 2025.51.1 | 316 | 12/19/2025 |
| 2025.49.1 | 247 | 12/6/2025 |