Naravel.Cache
0.2.0
dotnet add package Naravel.Cache --version 0.2.0
NuGet\Install-Package Naravel.Cache -Version 0.2.0
<PackageReference Include="Naravel.Cache" Version="0.2.0" />
<PackageVersion Include="Naravel.Cache" Version="0.2.0" />
<PackageReference Include="Naravel.Cache" />
paket add Naravel.Cache --version 0.2.0
#r "nuget: Naravel.Cache, 0.2.0"
#:package Naravel.Cache@0.2.0
#addin nuget:?package=Naravel.Cache&version=0.2.0
#tool nuget:?package=Naravel.Cache&version=0.2.0
Naravel.Cache
Named cache stores, tagging, scoping and locks for Naravel, built on Naravel.Foundation.
| Fact | Detail |
|---|---|
| Install | dotnet add package Naravel.Cache |
| Targets | .NET 10 |
| Needs | Naravel.Foundation, which NuGet installs with it |
| Providers | Naravel.Cache.Redis and Naravel.Cache.Memcached, for a cache every application instance shares |
What you get
- Named stores. The default store is
memory, so it runs with no configuration;CacheManagerpicks another store by name at run time. - The everyday calls.
SetAsyncwith a TTL,TryGetAsync,PullAsync, counters withIncrementAsync, andRememberAsync, which loads a value on a miss and stores it. - Scopes and tags.
ForUser(userId)andScope(...)prefix the keys, andTags("orders").FlushAsync()clears a tag without scanning keys. - Locks.
LockManagerandBlockAsyncrun a callback while holding a lock; with the Redis provider the lock is shared between instances. - A fixed-window rate limiter and a test fake.
AddNaravelRateLimitercounts attempts in a named store;CacheFakeis an in-memoryICacheStorefor your tests.
Quick start
using Naravel.Cache;
using Naravel.Cache.Abstractions;
builder.Services.AddNaravelCache(builder.Configuration); // no configuration needed: the default store is "memory"
builder.Services.AddSingleton(TimeProvider.System); // the clock the endpoint reads; a test registers its own
app.MapGet("/time", (ICacheStore cache, TimeProvider clock) =>
cache.RememberAsync("server-time", TimeSpan.FromSeconds(30),
() => Task.FromResult(clock.GetUtcNow().ToString("T"))));
The value stays the same for 30 seconds, then the factory runs again. Add a provider package from the list below to share one cache between several instances of the application.
Related packages
| Package | Adds |
|---|---|
Naravel.Cache.Redis |
Redis cache and distributed-lock providers |
Naravel.Cache.Memcached |
Memcached cache and lock providers |
Learn more
- Cache: English guide
- Changelog · Source and issues · MIT license
Part of Naravel: Laravel's names, .NET's type system. All Naravel packages share one version.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- Microsoft.Extensions.Caching.Memory (>= 10.0.14)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.14)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.14)
- Microsoft.Extensions.Options (>= 10.0.14)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.14)
- Naravel.Foundation (>= 0.2.0)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Naravel.Cache:
| Package | Downloads |
|---|---|
|
Naravel.Cache.Redis
Redis cache and distributed-lock providers for Naravel.Cache. |
|
|
Naravel.Queue.Coordination
Optional Naravel.Queue job middleware that coordinates workers through Naravel.Cache locks and rate limits: WithoutOverlapping, RateLimited and ThrottlesExceptions. |
|
|
Naravel.Cache.Memcached
Memcached cache and lock providers for Naravel.Cache. |
|
|
Naravel.Scheduling
Naravel task scheduling: a fluent, named schedule run by a hosted service, with overlap and one-server guards over Naravel.Cache locks. |
|
|
Naravel.Broadcasting
Typed real-time broadcasting over SignalR for Naravel: IBroadcastable events, channel authorization rules, signalr/log/null drivers and a test fake, built on Naravel.Foundation and Naravel.Events. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Release notes: https://github.com/km-arc/Naravel/releases/tag/v0.2.0 - full history: https://github.com/km-arc/Naravel/blob/main/CHANGELOG.md