SquidStd.Caching 0.27.0

dotnet add package SquidStd.Caching --version 0.27.0
                    
NuGet\Install-Package SquidStd.Caching -Version 0.27.0
                    
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="SquidStd.Caching" Version="0.27.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SquidStd.Caching" Version="0.27.0" />
                    
Directory.Packages.props
<PackageReference Include="SquidStd.Caching" />
                    
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 SquidStd.Caching --version 0.27.0
                    
#r "nuget: SquidStd.Caching, 0.27.0"
                    
#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 SquidStd.Caching@0.27.0
                    
#: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=SquidStd.Caching&version=0.27.0
                    
Install as a Cake Addin
#tool nuget:?package=SquidStd.Caching&version=0.27.0
                    
Install as a Cake Tool

<h1 align="center">SquidStd.Caching</h1>

In-memory backend for SquidStd.Caching. Provides an IMemoryCache-backed ICacheProvider with absolute TTL and eviction, wired to the shared typed ICacheService facade - registered with a single AddInMemoryCache() call.

The contract lives in SquidStd.Caching.Abstractions, so code written against ICacheService moves unchanged to a distributed cache: use this in-memory provider for single-process apps, tests, and local dev, then swap in SquidStd.Caching.Redis for production. Values are serialized as JSON in both cases, so cached shapes behave the same across providers.

Install

dotnet add package SquidStd.Caching

Usage

Register through the bootstrap - the provider is an ISquidStdService, so StartAsync / StopAsync manage its lifecycle for you:

using SquidStd.Caching.Abstractions.Interfaces;
using SquidStd.Caching.Extensions;
using SquidStd.Services.Core.Extensions;
using SquidStd.Services.Core.Services.Bootstrap;

var bootstrap = SquidStdBootstrap.Create(o => o.ConfigName = "myapp");
bootstrap.ConfigureServices(c => c.RegisterCoreServices().AddInMemoryCache());
await bootstrap.StartAsync();

Get / set with TTL

var cache = bootstrap.Resolve<ICacheService>();

await cache.SetAsync("greeting", "hello", TimeSpan.FromMinutes(5));
var value = await cache.GetAsync<string>("greeting");   // "hello", or default on a miss

var exists = await cache.ExistsAsync("greeting");        // true
var removed = await cache.RemoveAsync("greeting");       // true if the key existed

Omitting the TTL on SetAsync falls back to CacheOptions.DefaultTtl (no expiry when that is null).

Cache-aside with GetOrSetAsync

GetOrSetAsync returns the cached value, or runs the factory, stores the result, and returns it on a miss - the standard cache-aside pattern in one call:

public sealed record UserProfile(string Id, string Name);

var profile = await cache.GetOrSetAsync(
    $"user:{id}",
    async ct => await LoadProfileFromDatabaseAsync(id, ct),
    TimeSpan.FromMinutes(10)
);

Configuration

AddInMemoryCache takes an optional CacheOptions. Options are code-only - this package registers no YAML config section.

c.AddInMemoryCache(new CacheOptions
{
    DefaultTtl = TimeSpan.FromMinutes(5),
    KeyPrefix = "app:"
});
Property Default Purpose
DefaultTtl null TTL applied when a set call passes none; null means no expiry.
KeyPrefix string.Empty Prefix prepended to every key.

A connection-string overload is also available: AddInMemoryCache("memory://local?defaultTtlSeconds=300&keyPrefix=app:").

CacheMetricsProvider is registered as ICacheMetrics / IMetricProvider and exposes aggregate hit, miss, set, and remove counters plus the hit ratio to the metrics collection system.

Key types

Type Purpose
CacheRegistrationExtensions AddInMemoryCache(...) registration.
InMemoryCacheProvider IMemoryCache-backed ICacheProvider.
ICacheService Typed facade from SquidStd.Caching.Abstractions: get/set/TTL, GetOrSetAsync, exists/remove.
CacheOptions Default TTL and key prefix configuration.

License

MIT - part of SquidStd.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.27.0 0 7/7/2026
0.26.0 0 7/7/2026
0.25.0 40 7/6/2026
0.24.1 42 7/6/2026
0.24.0 40 7/6/2026
0.23.0 44 7/4/2026
0.22.0 44 7/4/2026
0.21.0 41 7/3/2026
0.20.0 34 7/3/2026
0.19.0 44 7/3/2026
0.18.0 43 7/3/2026
0.17.0 52 7/3/2026
0.16.0 47 7/3/2026
0.15.0 47 7/2/2026
0.14.1 58 7/2/2026
0.14.0 41 7/2/2026
0.13.0 41 7/2/2026
0.12.0 39 7/2/2026
0.11.0 43 7/2/2026
0.10.0 38 6/30/2026
Loading failed