AxisCache 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package AxisCache --version 2.0.0
                    
NuGet\Install-Package AxisCache -Version 2.0.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="AxisCache" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AxisCache" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AxisCache" />
                    
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 AxisCache --version 2.0.0
                    
#r "nuget: AxisCache, 2.0.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 AxisCache@2.0.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=AxisCache&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AxisCache&version=2.0.0
                    
Install as a Cake Tool

AxisCache — Documentation

🌐 Português (documentação navegável)

A tiny IAxisCache abstraction — five async operations (Get, Set, GetOrCreate, Remove, Exists), every one returning AxisResult, with cancellation flowing through AxisMediator. Two first-party adapter families ship in the box: a ready-made in-memory adapter (AxisMemoryCache) for single-process apps, and a two-tier SQL-backed adapter (AxisCache.Postgres / AxisCache.MySql) when cache state needs to survive a restart or be shared across instances. Drop in your own for Redis, Memcached or anything else.

public Task<AxisResult<Person>> GetByIdAsync(AxisEntityId personId)
    => cache.GetOrCreateAsync(
        key:        $"person:{personId}",
        factory:    () => repository.GetByIdAsync(personId),
        expiration: TimeSpan.FromMinutes(10));

Use this page as a map: read the trunk below (~5 min) and jump straight to the detail of the group you need — without reading hundreds of lines.


The trunk (read first)

The interface in 60 seconds

public interface IAxisCache
{
    Task<AxisResult<T?>>   GetAsync<T>(string key);
    Task<AxisResult>       SetAsync<T>(string key, T value, TimeSpan? expiration = null);
    Task<AxisResult<T>>    GetOrCreateAsync<T>(string key, Func<Task<AxisResult<T>>> factory, TimeSpan? expiration = null);
    Task<AxisResult>       RemoveAsync(string key);
    Task<AxisResult<bool>> ExistsAsync(string key);
}

Five methods. Every result is an AxisResult. Cancellation is implicit — the adapter pulls the CancellationToken from the current AxisMediator scope. Your application code never threads a token through cache calls. → The IAxisCache contract

GetOrCreateAsync — the most important operator

The cache-aside pattern, in one call. If the key is there, return it. If it isn't, run the factory, store its AxisResult<T> (only on success), return the value. If the factory fails, the failure flows through and nothing is cached. → Get-or-create pattern

In-memory adapter

AxisMemoryCache registers IAxisCache against Microsoft.Extensions.Caching.Memory:

services.AddAxisMemoryCache();   // wires IMemoryCache + IAxisCache → MemoryCacheAdapter

→ AxisMemoryCache adapter

SQL-backed adapter

Need the cache to survive a restart or be shared across instances? AxisCache.Postgres / AxisCache.MySql register the same IAxisCache, backed by a fast in-process L1 in front of a durable, shared L2 SQL table:

services.AddAxisCachePostgres(new AxisCacheRepositorySettings { ConnectionString = "Host=…" });

→ SQL adapter

Installation

dotnet add package AxisCache             # the abstraction (depends on AxisResult)
dotnet add package AxisMemoryCache       # the in-memory adapter
dotnet add package AxisCache.Postgres    # or AxisCache.MySql — the SQL-backed adapter

→ Full guide: Getting started


The map (jump to what you need)

Group You want to… Detail
Contract · IAxisCache the five operations and their semantics iaxiscache.md
Get-or-create · GetOrCreateAsync ⭐ cache-aside pattern with a failable factory get-or-create.md
In-memory · AxisMemoryCache the ready-made IMemoryCache adapter memory-adapter.md
SQL-backed · AxisCache.Postgres / AxisCache.MySql the ready-made two-tier adapter that survives a restart and is shared across instances sql-adapter.md
Custom adapter write your own (Redis, Memcached, hybrid) custom-adapter.md
Why? the case against direct IDistributedCache why-axiscache.md
Reference every method at a glance api-reference.md

Start here: Getting started · The IAxisCache contract · Why AxisCache?

Fundamentals: Get-or-create pattern · AxisMemoryCache adapter · SQL adapter

Reference & extras: Custom adapter · API reference


Design principles

  1. Five methods, no more. A bigger surface invites micro-optimisations that leak the vendor's model. Keep callers honest.
  2. Every result is an AxisResult. Cache failures are facts, not exceptions. The pipeline decides what to do with them.
  3. Cancellation is implicit. The adapter pulls the token from IAxisMediatorAccessor, so no signature has to carry it.
  4. The adapter is replaceable. services.AddAxisMemoryCache() is one line; swap it for AddAxisCachePostgres()/AddAxisCacheMySql() — or a custom AddAxisRedisCache() — and nothing in the application changes.
  5. GetOrCreateAsync is the headline. The factory is allowed to fail — that failure is not cached.

License

Apache 2.0

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 (2)

Showing the top 2 NuGet packages that depend on AxisCache:

Package Downloads
AxisCache.Repository

Part of the Axis Framework — an opinionated, ports-and-adapters .NET framework.

AxisMemoryCache

Part of the Axis Framework — an opinionated, ports-and-adapters .NET framework.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.0 319 7/21/2026
2.1.1 160 7/17/2026
2.1.0 163 7/17/2026
2.0.1 168 7/15/2026
2.0.0 179 7/15/2026