Provides guidance on ABP's typed hybrid cache (in-memory L1 + distributed L2) with stampede protection, including GetOrCreateAsync, SetAsync, RemoveAsync, and configuration options.
Ships in abp-runtime. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Guidance for ABP's typed hybrid cache: a fast in-memory L1 tier backed by a distributed L2 tier, with stampede protection. All APIs below are verified against ABP source. Inject everything via constructor.
GetOrCreateAsync to return a cached value or compute-and-store it on a miss, with built-in stampede protection so concurrent callers don't all run the factory.AbpHybridCacheOptions / HybridCacheEntryOptions.IDistributedCache<T> / GetOrAddAsync) or distributed locking (IAbpDistributedLock) — use the distributed-caching-and-locking skill. If you only need one distributed tier and don't need a local in-memory copy, that abstraction is the simpler fit.IHybridCache<TCacheItem> and IHybridCache<TCacheItem, TCacheKey> (namespace Volo.Abp.Caching.Hybrid, package Volo.Abp.Caching) are typed wrappers over Microsoft.Extensions.Caching.Hybrid.HybridCache. AbpCachingModule registers AddHybridCache() and binds the open generics to AbpHybridCache<> / AbpHybridCache<,> by default, so nothing extra is needed to inject them. HybridCache keeps a fast in-memory L1 tier and, when a distributed cache (L2) is configured, reads through to L2 on an L1 miss and populates both tiers on a write — plus it protects against cache stampede so concurrent misses for the same key run the factory once. (The ABP wrapper writes with tags: null and adds no cross-instance L1 invalidation of its own.)
TCacheItem is a serializable class (where TCacheItem : class). ABP handles JSON serialization (via its own serializer factory), tenant-scoped key normalization, and a per-type cache name automatically. The single-generic IHybridCache<TCacheItem> uses a string key and is just IHybridCache<TCacheItem, string> with an extra InternalCache property; the two-generic IHybridCache<TCacheItem, TCacheKey> supports typed keys.
Define a cache item as a plain class:
public class ProductCacheItem
{
public string Name { get; set; }
public decimal Price { get; set; }
}
Inject and use it. GetOrCreateAsync is the go-to method — it returns the cached value or runs your factory to produce and store it:
public class ProductAppService : ApplicationService
{
private readonly IHybridCache<ProductCacheItem> _cache;
private readonly IRepository<Product, Guid> _repo;
public ProductAppService(
IHybridCache<ProductCacheItem> cache,
IRepository<Product, Guid> repo)
{
_cache = cache;
_repo = repo;
}
public async Task<ProductCacheItem?> GetAsync(Guid id)
{
return await _cache.GetOrCreateAsync(
id.ToString(),
async () =>
{
var product = await _repo.GetAsync(id);
return new ProductCacheItem { Name = product.Name, Price = product.Price };
},
() => new HybridCacheEntryOptions
{
Expiration = TimeSpan.FromMinutes(30)
});
}
}
From IHybridCache<TCacheItem, TCacheKey>:
Task<TCacheItem?> GetOrCreateAsync(
TCacheKey key,
Func<Task<TCacheItem>> factory,
Func<HybridCacheEntryOptions>? optionsFactory = null,
bool? hideErrors = null,
bool considerUow = false,
CancellationToken token = default);
Task SetAsync(
TCacheKey key,
TCacheItem value,
HybridCacheEntryOptions? options = null,
bool? hideErrors = null,
bool considerUow = false,
CancellationToken token = default);
Task RemoveAsync(
TCacheKey key,
bool? hideErrors = null,
bool considerUow = false,
CancellationToken token = default);
Task RemoveManyAsync(
IEnumerable<TCacheKey> keys,
bool? hideErrors = null,
bool considerUow = false,
CancellationToken token = default);
Notes:
GetOrCreateAsync takes an optionsFactory (a Func<HybridCacheEntryOptions>), while SetAsync takes an options value directly. They differ when omitted: SetAsync falls back to the cache's configured default options (GlobalHybridCacheEntryOptions or a matching ConfigureCache entry); GetOrCreateAsync just passes your optionsFactory through, so omitting it applies no ABP per-cache options to that call — the underlying HybridCache defaults apply. Pass an optionsFactory when you want per-call/per-cache expiration on a GetOrCreateAsync.hideErrors defaults to the global setting (AbpHybridCacheOptions.HideErrors, default true): when a cache error is hidden it is logged/forwarded to the exception notifier and the call returns null — it does not re-run your factory or fall back to a source read, so handle a null result. With hideErrors: false the exception propagates.considerUow (default false) keeps writes in the current unit of work until it completes, so the real cache is only written on UOW completion.RemoveAsync removes a single key; RemoveManyAsync removes a batch in one call.HybridCacheEntryOptions is the Microsoft type from Microsoft.Extensions.Caching.Hybrid (e.g. Expiration, LocalCacheExpiration), not an ABP type.AbpHybridCacheOptionsConfigure in a module's Configure<AbpHybridCacheOptions>(...):
Configure<AbpHybridCacheOptions>(options =>
{
options.GlobalHybridCacheEntryOptions = new HybridCacheEntryOptions
{
Expiration = TimeSpan.FromMinutes(20)
};
// Per-cache-item entry options
options.ConfigureCache<ProductCacheItem>(new HybridCacheEntryOptions
{
Expiration = TimeSpan.FromMinutes(5)
});
});
AbpHybridCacheOptions exposes:
HideErrors (default true) — hide (log) or throw cache exceptions.KeyPrefix — present on the type, but not read by the hybrid key normalization in this ABP version. The effective key prefix comes from AbpDistributedCacheOptions.KeyPrefix (applied by IDistributedCacheKeyNormalizer); set the prefix there, not here.GlobalHybridCacheEntryOptions — default HybridCacheEntryOptions when no per-cache configurator matches.CacheConfigurators — the list backing the ConfigureCache(...) overloads (ConfigureCache<TCacheItem>(...), ConfigureCache(Type, ...), ConfigureCache(string cacheName, ...)).The cache name defaults to the item type's full name (namespace-qualified) with a trailing CacheItem removed (CacheNameAttribute.GetCacheName); override it with [CacheName("...")] on the item class. Items marked [IgnoreMultiTenancy] skip tenant-scoped key normalization.
Out of the box the hybrid cache's L2 relies on the registered IDistributedCache, which defaults to the per-instance in-memory distributed cache. For a real shared L2 across instances, add a distributed cache provider such as Volo.Abp.Caching.StackExchangeRedis (depend on AbpCachingStackExchangeRedisModule and set the Redis connection string). The typed IHybridCache<T> API stays identical; only the L2 backing store changes.
IHybridCache<T> and IHybridCache<T, TKey> resolve from DI because AbpCachingModule registers them by default (no extra wiring needed for the abstraction itself).where TCacheItem : class); the hybrid cache serializes items as JSON.Volo.Abp.Caching.StackExchangeRedis + AbpCachingStackExchangeRedisModule + Redis connection string) is wired; the default in-memory L2 is per-instance and not shared.IDistributedCache<T> / GetOrAddAsync from the distributed-caching-and-locking skill instead.GetOrCreateAsync on the hybrid cache (not GetOrAddAsync, which belongs to IDistributedCache<T>).GetOrCreateAsync takes an optionsFactory delegate (Func<HybridCacheEntryOptions>), whereas SetAsync takes an options value directly.HideErrors defaults to true, so a hidden L2 error is logged and the call returns null (it does not re-run the factory); handle the null. Set hideErrors: false if you want it to throw.AbpHybridCacheOptions.KeyPrefix and expecting a prefix — it isn't wired in this version; configure AbpDistributedCacheOptions.KeyPrefix instead.TCacheItem must be a class ABP can serialize to JSON.What SKILL.md sets; muted values are Claude Code's defaults
10 skills in this plugin
/background-jobs-and-eventsIn-process/cross-service events, entity change reactions, deferred/recurring background work. USE FOR: ILocalEventBus / IDistributedEventBus, EntityCreated/Updated/DeletedEventData, [EventName] ETOs, IBackgroundJobManager jobs, AsyncPeriodicBackgroundWorkerBase workers. DO NOT USE FOR: distributed cache/lock (distributed-caching-and-locking); SignalR push (add-signalr-realtime); microservice message contracts (design-module-and-service-communication)./cache-entitiesRead-only single-entity-by-id caching via the generic IEntityCache abstraction (cache to the entity or a DTO), auto-invalidated. USE FOR: AddEntityCache, caching to entity or DTO, batch lookups (FindMany/GetMany), expiration, EntityCacheWithObjectMapper mapping. DO NOT USE FOR: general key/value caching or distributed locks (distributed-caching-and-locking); querying/persisting entities (ef-core-integration or mongodb-integration)./configure-app-urlsNamed application roots and external URLs with AppUrlOptions, resolved tenant-aware via IAppUrlProvider. USE FOR: AppUrlOptions.Applications; RootUrl and named Urls; email links; cross-application links; tenantId and tenantName placeholders; redirect allow-list checks. DO NOT USE FOR: rendering the email body (render-text-templates) or sending it (send-emails); remote service base addresses (consume-remote-services); resolving tenants by domain (configure-multi-tenancy)./configure-production-hostingRelease checklist for hosting an ABP app in production behind a reverse proxy or clustered. USE FOR: forwarded headers, shared Data Protection keys, cluster cache/lock, single/multi-instance jobs/workers, SignalR scale-out, shared KeyPrefix. DO NOT USE FOR: the cache/lock APIs (distributed-caching-and-locking); job/worker mechanics (background-jobs-and-events); SignalR hubs (add-signalr-realtime); OpenIddict prod certs (configure-openiddict-authentication)./distributed-caching-and-lockingTyped distributed caching and cross-instance distributed locking. USE FOR: typed IDistributedCache / GetOrAddAsync (Redis-backed), IAbpDistributedLock.TryAcquireAsync, AbpDistributedCacheOptions / [CacheName]. DO NOT USE FOR: per-entity caching (cache-entities); multi-tier hybrid cache (use-hybrid-caching); events, background jobs, or workers (background-jobs-and-events); settings/features (manage-settings-and-features); data filters (apply-data-filters)./render-text-templatesRender text templates (Scriban or Razor) in ABP. USE FOR: TemplateDefinitionProvider, TemplateDefinition + WithScribanEngine/WithRazorEngine, WithVirtualFilePath content, ITemplateRenderer.RenderAsync, per-culture localization, layouts, the Razor safety boundary. DO NOT USE FOR: sending the rendered body as email (send-emails); embedding .tpl files (manage-virtual-files); localization resources (localize-applications)./abp-runtime:use-hybrid-cachingfrom abp-runtime
npx claudepluginhub abpframework/abp-skills --plugin abp-runtimeOther plugins' skills for the same job