XiHan.Framework.Caching.Abstractions 5.0.0-rc.2

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

XiHan.Framework.Caching.Abstractions

关于

XiHan.Framework.Caching.Abstractions 定义缓存的契约:字节存储 ICacheStore、类型化缓存 ICache / ISharedCache、序列化器、分布式锁,以及按幂等键去重的 Idempotency 中间件。不包含存储实现。

主要特性

  • 进程内缓存与跨进程共享缓存两套门面,支持批量读写与 GetOrCreateAsync
  • 绝对或滑动过期
  • 基于存储的分布式租约锁
  • IDistributedCache 适配与操作调用的幂等去重
  • GenerationCache<T>:按范围失效、丢弃失效之前开始的读取的读穿缓存区,装了两级缓存时失效作用于所有实例
  • 组件经 CacheSerializerRegistration.AddTypeInfo 登记自己放进缓存的类型,应用的序列化上下文不必认识它们

如何使用

安装

dotnet add package XiHan.Framework.Caching.Abstractions --prerelease

使用

通常由实现包带入;写业务代码或自定义缓存提供程序时才直接引用。实现包有 Caching.InMemory、Caching.Redis、Caching.Remote、Caching.Hybrid。业务代码里这样用:

var cache = context.Services.GetRequiredService<ISharedCache>();
var profile = await cache.GetOrCreateAsync(
    new CacheKey($"profile:{id}"),
    ct => LoadAsync(id, ct),
    CacheEntryOptions.Expires(TimeSpan.FromMinutes(5)),
    ct);

存储不可达时抛出携带 CACHING_UNAVAILABLE_001 的 FrameworkException,不会伪装成未命中。

数据会被写入改变、写入后要让一批条目一起失效时,用 GenerationCache<T>:

var prices = new GenerationCache<PriceList>(cache, "acme:prices", TimeSpan.FromMinutes(5), logger);
// 范围是租户、条目是类别;未命中的位置一次交给 loadMany 查源,查源失败不写缓存
var read = await prices.GetOrLoadManyAsync([new GenerationCacheKey(tenantId, "books")], loadMany, ct);
// 租户调价:这个租户下的条目一起作废,失效之前开始的读取写回的旧值不会被当作命中
await prices.InvalidateAsync([tenantId], ct);

缓存后端故障时读取直接查源、不写回;失效把异常抛给调用方,由它决定拒绝写入还是记日志。

主要类型

此库提供的主要类型:

  • ICache、ISharedCache:类型化缓存门面
  • ICacheStore:字节级存储,提供程序实现它
  • CacheKey、CacheEntryOptions:键与过期选项
  • IDistributedLock、LockHandle:分布式锁
  • ICacheSerializer、JsonCacheSerializer、CacheSerializerRegistration、CacheTypeInfoSource:共享缓存的值序列化与组件类型的登记
  • GenerationCache<T>、GenerationCacheKey、GenerationCacheEntry<T>:按范围失效的缓存区
  • IdempotencyMiddleware:按幂等键去重

更多文档

相关包

反馈与贡献

XiHan.Framework.Caching.Abstractions 以 MIT 许可证 开源。欢迎到 GitHub 仓库 提交问题和贡献。

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

Showing the top 5 NuGet packages that depend on XiHan.Framework.Caching.Abstractions:

Package Downloads
XiHan.Framework.Persistence.Abstractions

曦寒框架持久化抽象包

XiHan.Framework.Caching.InMemory

曦寒框架缓存的内存默认实现

XiHan.Framework.Profiles.Standard

曦寒框架 Standard 组合包

XiHan.Framework.Caching.Redis

曦寒框架缓存的 Redis 提供程序

XiHan.Framework.Caching.Hybrid

曦寒框架缓存的两级缓存提供程序

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0-rc.2 0 11/15/2026
5.0.0-rc.1 174 11/13/2026
5.0.0-preview.3 147 11/11/2026
5.0.0-preview.2 279 11/6/2026
5.0.0-preview.1 233 11/4/2026