Provides typed distributed caching and cross-instance distributed locking for ABP applications using Redis. Includes guidance on IDistributedCache and IAbpDistributedLock.
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 distributed cache and distributed lock, plus a short pointer on data filters, settings, and features. All APIs below are verified against ABP source. Inject everything via constructor.
IDistributedCache<TCacheItem> (Redis-backed).GetOrAddAsync to return a cached value or compute-and-store it on a miss.IAbpDistributedLock).IDistributedCache<TCacheItem> (namespace Volo.Abp.Caching) is a typed wrapper over Microsoft.Extensions.Caching.Distributed.IDistributedCache. TCacheItem is a serializable class (where TCacheItem : class); ABP handles JSON serialization, tenant-scoped keys, and a per-type cache name automatically. The default key is a string; a two-generic overload IDistributedCache<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. GetOrAddAsync 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 IDistributedCache<ProductCacheItem> _cache;
private readonly IRepository<Product, Guid> _repo;
public ProductAppService(
IDistributedCache<ProductCacheItem> cache,
IRepository<Product, Guid> repo)
{
_cache = cache;
_repo = repo;
}
public async Task<ProductCacheItem?> GetAsync(Guid id)
{
return await _cache.GetOrAddAsync(
id.ToString(),
async () =>
{
var product = await _repo.GetAsync(id);
return new ProductCacheItem { Name = product.Name, Price = product.Price };
},
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30)
});
}
}
Verified method signatures:
Task<TCacheItem?> GetAsync(TCacheKey key, bool? hideErrors = null,
bool considerUow = false, CancellationToken token = default);
Task SetAsync(TCacheKey key, TCacheItem value, DistributedCacheEntryOptions? options = null,
bool? hideErrors = null, bool considerUow = false, CancellationToken token = default);
Task<TCacheItem?> GetOrAddAsync(TCacheKey key, Func<Task<TCacheItem>> factory,
Func<DistributedCacheEntryOptions>? optionsFactory = null, bool? hideErrors = null,
bool considerUow = false, CancellationToken token = default);
Task RemoveAsync(TCacheKey key, bool? hideErrors = null,
bool considerUow = false, CancellationToken token = default);
Task RefreshAsync(TCacheKey key, bool? hideErrors = null, CancellationToken token = default);
Notes:
hideErrors defaults to the global setting (true): cache errors are logged, not thrown, so a Redis outage degrades to source reads rather than failing requests.AbpDistributedCacheOptions (configure in a module's Configure<...>) exposes GlobalCacheEntryOptions, KeyPrefix, and HideErrors.CacheItem suffix stripped (e.g. MyApp.Books.BookCacheItem → MyApp.Books.Book); override it with [CacheName("...")] on the item class.The in-memory IDistributedCache is per-instance and not shared. For a real distributed cache add the Volo.Abp.Caching.StackExchangeRedis package, depend on AbpCachingStackExchangeRedisModule, and set the Redis connection string in appsettings.json. The typed IDistributedCache<T> API stays identical.
IAbpDistributedLock (namespace Volo.Abp.DistributedLocking) coordinates a critical section across multiple app instances — only one holder at a time for a given lock name. The default implementation (MedallionAbpDistributedLock) wraps the Medallion DistributedLock library.
Task<IAbpDistributedLockHandle?> TryAcquireAsync(
string name, TimeSpan timeout = default, CancellationToken cancellationToken = default);
TryAcquireAsync returns an IAbpDistributedLockHandle (which is IAsyncDisposable) when the lock is taken, or null when it could not be acquired within timeout (default 0 = don't wait). Always check for null and dispose the handle with await using:
public class ReportGenerator : ITransientDependency
{
private readonly IAbpDistributedLock _distributedLock;
public ReportGenerator(IAbpDistributedLock distributedLock) => _distributedLock = distributedLock;
public async Task GenerateAsync()
{
await using (var handle = await _distributedLock.TryAcquireAsync("daily-report"))
{
if (handle is null)
{
return; // another instance holds the lock
}
// critical section — runs on a single instance
}
}
}
The base Volo.Abp.DistributedLocking package needs a backing synchronization provider registered in DI. A common choice is Redis via Medallion's RedisDistributedSynchronizationProvider (register it as IDistributedLockProvider); other Medallion backends (SQL Server, Azure, ZooKeeper) work too. Without a registered provider, IAbpDistributedLock is not functional.
Data filters — IDataFilter (namespace Volo.Abp.Data) toggles global query filters like ISoftDelete (namespace Volo.Abp) and IMultiTenant (Volo.Abp.MultiTenancy) for a scope. Wrap in a using:
using (_dataFilter.Disable<ISoftDelete>())
{
var all = await _repo.GetListAsync(); // includes soft-deleted rows
}
Settings — ISettingProvider (namespace Volo.Abp.Settings) reads config-like values with provider fallback. Providers are consulted highest-to-lowest priority (user → tenant → global → configuration → default): the first provider that returns a non-null value wins. Core method is GetOrNullAsync(name); extension methods add IsTrueAsync(name) and GetAsync<T>(name, defaultValue) (where T : struct). Declare settings by deriving from SettingDefinitionProvider and overriding void Define(ISettingDefinitionContext context), adding SettingDefinition instances via context.Add(...).
Features — IFeatureChecker (namespace Volo.Abp.Features) gates functionality per tenant/edition. Use IsEnabledAsync(name) for booleans and GetOrNullAsync(name) / GetAsync<T>(name) for values. Declare features by deriving from FeatureDefinitionProvider, overriding void Define(IFeatureDefinitionContext context), calling context.AddGroup(...) then group.AddFeature(name, defaultValue, ...).
IDistributedCache<T> and IAbpDistributedLock resolve from DI once their packages/providers are wired.Volo.Abp.Caching.StackExchangeRedis package + AbpCachingStackExchangeRedisModule dependency + Redis connection string are in place (the in-memory cache is per-instance and won't be shared).RedisDistributedSynchronizationProvider registered as IDistributedLockProvider) is in DI — without it IAbpDistributedLock is not functional.TryAcquireAsync on the same name gets null while the first holds the handle.TryAcquireAsync for null — it returns null when the lock isn't acquired within timeout (default 0 = don't wait). Treat a null handle as "someone else holds it" and skip the critical section.await using on the lock handle — the handle is IAsyncDisposable; dispose it to release the lock.IAbpDistributedLock does nothing useful.hideErrors defaults to true, so a Redis outage is logged and degrades to source reads instead of failing the request.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/abp-runtime:distributed-caching-and-lockingfrom abp-runtime
npx claudepluginhub abpframework/abp-skills --plugin abp-runtime10 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)./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)./secure-web-requestsABP ASP.NET Core CSRF protection and response security headers. USE FOR: AbpAntiForgeryOptions and antiforgery cookies; MVC antiforgery validation; IAbpAntiForgeryManager; Blazor/WebAssembly antiforgery; AbpSecurityHeadersOptions; UseAbpSecurityHeaders; CSP and script nonces. DO NOT USE FOR: token issuance/API auth (configure-openiddict-authentication); permissions (permissions-and-authorization); MVC/Razor pages (mvc-razor-ui); Blazor components (blazor-ui).Other plugins' skills for the same job