LiteAPI.Cache 1.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package LiteAPI.Cache --version 1.2.2
                    
NuGet\Install-Package LiteAPI.Cache -Version 1.2.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="LiteAPI.Cache" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LiteAPI.Cache" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="LiteAPI.Cache" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LiteAPI.Cache --version 1.2.2
                    
#r "nuget: LiteAPI.Cache, 1.2.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.
#:package LiteAPI.Cache@1.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LiteAPI.Cache&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=LiteAPI.Cache&version=1.2.2
                    
Install as a Cake Tool

LiteAPI.Cache - JustCache

GC-free, cross-platform in-memory cache for .NET backed by Rust.

JustCache is a high-performance memory cache system built to bypass .NET's garbage collector by leveraging native Rust memory management. Designed for low-latency, high-throughput scenarios where predictability and performance are essential.


πŸš€ Key Features

  • ⚑ GC-Free: No garbage collection pressure in .NET
  • 🧠 Native performance using Rust under the hood
  • πŸ’Ό Cross-platform: Supports Windows, Linux, and macOS
  • πŸ”’ Thread-safe read/write access
  • πŸ’Ύ Supports strings, byte arrays, and JSON-serializable objects
  • 🧱 Phase 1 (Core Redis types): Hashes, Lists, Sets, Sorted Sets
  • πŸ›‘οΈ Phase 2 (Reliability): LRU eviction, TTL + active expiry thread, AOF replay, binary-safe keys
  • πŸ“£ Phase 3 (Messaging): Pub/Sub, keyspace notifications, Streams
  • 🧭 Phase 4 (Querying): JSON Path GET/SET, numeric secondary index + find, lightweight eval
  • 🧩 Interop via NativeAOT or P/Invoke
  • πŸ›‘οΈ Safe memory management without leaks

πŸ“¦ Installation

Install the NuGet package:

dotnet add package LiteAPI.Cache

πŸ”§ Requires a precompiled native Rust dynamic library. See the documentation or GitHub repository for details.


βš™οΈ Usage

  • Initialize the cache at application startup
  • Set/Get data by key (supports string, bytes, and object types)
  • Remove individual keys or clear all
  • Interop with Rust is handled internallyβ€”no manual marshaling needed
using LiteAPI.Cache;

string key = "example_key";
Student student = Student.Random(1);

// Initialize the cache and perform operations
JustCache.Initialize();

// Set an object in the cache
JustCache.SetObject(key, student);

// Retrieve the object from the cache
student = JustCache.GetObject<Student>(key) ?? Student.Random(2);

// Display the retrieved object
Console.WriteLine(student);

// Remove the object from the cache
JustCache.Remove(key);

// Clear all cached objects
JustCache.ClearAll();

🧱 Phase 1: Rich Data Structures (Core Redis)

Phase 1 adds Redis-like data structures implemented in Rust and exposed via the C# JustCache API.

Hashes (HSET, HGET, HGETALL)

JustCache.HSetString("user:1", "name", "Alice");
JustCache.HSetString("user:1", "city", "Tashkent");

string? name = JustCache.HGetString("user:1", "name");
var all = JustCache.HGetAll("user:1"); // Dictionary<string, byte[]>

Lists (LPUSH, RPOP, LRANGE)

JustCache.LPushString("recent", "a");
JustCache.LPushString("recent", "b");

List<string> items = JustCache.LRangeStrings("recent", 0, -1);
string? last = JustCache.RPopString("recent");

Sets (SADD, SISMEMBER)

bool added = JustCache.SAddString("tags", "x");
bool isMember = JustCache.SIsMemberString("tags", "x");

Sorted Sets (ZADD, ZRANGE)

JustCache.ZAdd("leaderboard", 5, "alice");
JustCache.ZAdd("leaderboard", 10, "bob");

List<string> members = JustCache.ZRange("leaderboard", 0, -1);

πŸ›‘οΈ Phase 2: Reliability & Advanced Persistence

Phase 2 focuses on predictable memory usage, better expiry behavior, and crash recovery.

LRU eviction

Configure a maximum number of items; least-recently-used entries are evicted when capacity is exceeded.

JustCache.SetMaxItems(100_000);
int current = JustCache.Count;

TTL + active expiry

Keys can be written with TTL or updated with expiry. The Rust side runs a small background thread to proactively remove expired entries.

JustCache.SetStringWithTtl("session:1", "value", TimeSpan.FromSeconds(10));
bool ok = JustCache.Expire("session:1", TimeSpan.FromSeconds(5));

// Redis-like TTL semantics:
// -2: key does not exist
// -1: no expiry
// >=0: milliseconds remaining
long ttlMs = JustCache.TtlMs("session:1");

AOF (Append Only File) replay

Enable AOF logging to a file, then replay it to rebuild state after a crash/restart.

JustCache.EnableAof("./justcache.aof");
JustCache.SetString("aof:k1", "1");
JustCache.DisableAof();

JustCache.ClearAll();
JustCache.LoadAof("./justcache.aof");

Binary-safe keys

Use byte[] keys (in addition to string keys), similar to Redis.

byte[] key = new byte[] { 0, 1, 2, 255 };
JustCache.Set(key, System.Text.Encoding.UTF8.GetBytes("bin"));
byte[]? val = JustCache.Get(key);
JustCache.Remove(key);

βœ… Verifying Phase 1 / Phase 2 (C#)

The repository includes small runners in TestApp to validate Rust + P/Invoke interop.

  1. Build the Rust native library:
cd RustLib
cargo build --release
  1. Build the .NET solution (copies the native artifact into outputs):
dotnet build -c Release
  1. Run verification:
cd TestApp/bin/Release/net9.0
./TestApp.exe phase1
./TestApp.exe phase2

πŸ“£ Phase 3: Messaging & Events

Pub/Sub

ulong sub = JustCache.Subscribe("orders");
JustCache.PublishString("orders", "created:123");

if (JustCache.TryPoll(sub, out var msg))
{
	Console.WriteLine(msg.Channel);
	Console.WriteLine(msg.PayloadAsString());
}

JustCache.Unsubscribe(sub);

Keyspace notifications (expired / evicted)

JustCache.ClearNotifications();

// cause an eviction
JustCache.SetMaxItems(2);
JustCache.SetString("k1", "1");
JustCache.SetString("k2", "2");
JustCache.SetString("k3", "3");

while (JustCache.TryPollNotification(out var n))
{
	Console.WriteLine(n);
}

Streams (XADD / XRANGE)

ulong id1 = JustCache.XAdd("stream:orders", Encoding.UTF8.GetBytes("a"));
ulong id2 = JustCache.XAdd("stream:orders", Encoding.UTF8.GetBytes("b"));

var items = JustCache.XRange("stream:orders", id1, id2);
foreach (var it in items)
	Console.WriteLine($"{it.Id} {Encoding.UTF8.GetString(it.Payload)}");

βœ… Verifying Phase 3 (C#)

cd RustLib
cargo build --release

cd ..
dotnet build -c Release

cd TestApp/bin/Release/net9.0
./TestApp.exe phase3

🧭 Phase 4: Querying & Scripting

Phase 4 adds basic querying features on top of JSON values stored as bytes.

JSON Path (GET / SET)

JustCache.SetString("j:1", "{\"name\":\"a\",\"age\":10,\"tags\":[\"x\"]}");

string? age = JustCache.JsonGetString("j:1", "$.age"); // "10"

JustCache.JsonSet("j:1", "$.age", "11");
JustCache.JsonSet("j:1", "$.tags[1]", "\"y\"");

Supported path tokens: $, .field, [index].

Numeric secondary index + Find

Create an index for a top-level numeric JSON field and query keys.

JustCache.CreateNumericIndex("age");

var keys = JustCache.FindKeys("age >= 18");
foreach (var k in keys)
	Console.WriteLine(k);

Lightweight Eval

JustCache.EvalString("SET e:k1 hello");   // "OK"
JustCache.EvalString("GET e:k1");         // "hello"
JustCache.EvalString("DEL e:k1");         // "1" or "0"

JustCache.EvalString("JSON.SET e:j $.a 1");
JustCache.EvalString("JSON.GET e:j $.a");

βœ… Verifying Phase 4 (C#)

cd RustLib
cargo build --release

cd ..
dotnet build -c Release

cd TestApp/bin/Release/net9.0
./TestApp.exe phase4

🧠 Why JustCache?

  • πŸš€ Ultra-fast native cache access
  • βœ… No impact on .NET GC or memory fragmentation
  • 🧩 Drop-in utility for microservices, real-time systems, or edge apps
  • πŸ” Useful for caching config, lookup tables, auth sessions, and more

πŸͺͺ License

MIT License Β© 2025 LiteAPI


πŸ’¬ Feedback

Found a bug or want a feature? Open an issue or PR on GitHub.

πŸ› οΈ Contributing

We welcome contributions! Please see the CONTRIBUTING.md for guidelines.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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 is compatible.  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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 93 1/20/2026
2.0.0 93 1/20/2026
1.2.2 91 1/19/2026
1.1.2 411 11/19/2025
1.1.1 410 11/19/2025
1.1.0 554 11/18/2025
1.0.1 287 8/7/2025
1.0.0 269 8/7/2025

add linux support