pvNugsCacheNc10Memory 10.0.3
dotnet add package pvNugsCacheNc10Memory --version 10.0.3
NuGet\Install-Package pvNugsCacheNc10Memory -Version 10.0.3
<PackageReference Include="pvNugsCacheNc10Memory" Version="10.0.3" />
<PackageVersion Include="pvNugsCacheNc10Memory" Version="10.0.3" />
<PackageReference Include="pvNugsCacheNc10Memory" />
paket add pvNugsCacheNc10Memory --version 10.0.3
#r "nuget: pvNugsCacheNc10Memory, 10.0.3"
#:package pvNugsCacheNc10Memory@10.0.3
#addin nuget:?package=pvNugsCacheNc10Memory&version=10.0.3
#tool nuget:?package=pvNugsCacheNc10Memory&version=10.0.3
pvNugsCacheNc10Memory
Overview
pvNugsCacheNc10Memory is a high-performance, thread-safe in-memory caching solution for .NET Core 10 applications. Built on top of Microsoft.Extensions.Caching.Memory, it provides a simple abstraction for storing and retrieving cached data with configurable time-to-live (TTL) settings and integrated logging.
Key Features
- In-memory caching using
IMemoryCache - Configurable default and per-item TTL
- Thread-safe operations
- Trace logging for cache hit/miss/set/remove events
- Strongly-typed generic API
- Async methods with cancellation token support
- Simple dependency injection setup
- Configuration-driven defaults
Installation
dotnet add package pvNugsCacheNc10Memory
Requirements
- .NET Core 10.0 or higher
- C# 13.0 or higher
Quick Start
1) Configure appsettings.json
{
"PvNugsCacheConfig": {
"DefaultTimeToLive": "00:10:00"
}
}
2) Register services
using pvNugsCacheNc10Memory;
var builder = WebApplication.CreateBuilder(args);
// Registers IMemoryCache and IPvNugsCache
builder.Services.TryAddPvNugsCacheMemory(builder.Configuration);
var app = builder.Build();
3) Use the cache
using pvNugsCacheNc10Abstractions;
public class MyService
{
private readonly IPvNugsCache _cache;
public MyService(IPvNugsCache cache)
{
_cache = cache;
}
public async Task<User> GetUserAsync(string userId)
{
var cacheKey = $"user:{userId}";
var cachedUser = await _cache.GetAsync<User>(cacheKey);
if (cachedUser != null)
return cachedUser;
var user = await LoadUserFromDatabaseAsync(userId);
await _cache.SetAsync(cacheKey, user, TimeSpan.FromMinutes(5));
return user;
}
public async Task UpdateUserAsync(User user)
{
await SaveUserToDatabaseAsync(user);
await _cache.RemoveAsync($"user:{user.Id}");
}
}
API Reference
IPvNugsCache
SetAsync
Task SetAsync<TValue>(
string key,
TValue value,
TimeSpan? timeToLive = null,
CancellationToken cancellationToken = default)
Stores a value in the cache with an optional TTL.
GetAsync
Task<TValue?> GetAsync<TValue>(
string key,
CancellationToken cancellationToken = default)
Retrieves a value from the cache.
RemoveAsync
Task RemoveAsync(
string key,
CancellationToken cancellationToken = default)
Removes a cached item.
Configuration
PvNugsCacheConfig
| Property | Type | Description |
|---|---|---|
DefaultTimeToLive |
TimeSpan? |
Default expiration time for cached items. If null, items do not expire automatically. |
Logging
The cache integrates with the pvNugs logging abstractions and emits trace-level logs for key operations:
- Cache hit
- Cache miss
- Cache set
- Cache remove
Dependencies
Microsoft.Extensions.Caching.Memory(10.0.9)Microsoft.Extensions.Options.ConfigurationExtensions(10.0.9)pvNugsCacheNc10Abstractions(10.0.0)
Related Packages
pvNugsCacheNc10Abstractions- cache interface definitionspvNugsLoggerNc10Abstractions- logging abstractionspvNugsLoggerNc10Seri- Serilog-based logger implementation
License
This project is licensed under the MIT License.
| 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.9)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.9)
- pvNugsCacheNc10Abstractions (>= 10.0.1)
- pvNugsLoggerNc10Abstractions (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Updated pvNugsLoggerNc10Abstractions dependency from 10.0.0 to 10.0.1