Prompt file imported from smss123/ABP-ai-skills (
.windsurf/workflows/abp-caching.md). Copyright stays with the author.
ABP Caching Scaffold
A Windsurf Cascade workflow that creates a cache item class, wires up IDistributedCache<T> usage, and handles cache invalidation.
Inputs
Before starting, ask the user:
- What to cache — entity name or data description
- Cache key — simple string/Guid, or compound key?
- TTL — how long should the cached value live?
- Invalidation triggers — which operations should clear the cache?
- Redis? — Yes (production) / No (in-memory)
Step 1 — Read reference file
Read abp-dev/references/caching.md before generating any code.
Step 2 — Create the cache item class
src/Acme.BookStore.Application/<Entity>s/<Entity>CacheItem.cs
using Volo.Abp.Caching;
namespace Acme.BookStore.<Entity>s;
[CacheName("<Entity>")]
public class <Entity>CacheItem
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
// include only what consumers need — not the full entity
}
Step 3 — Inject and use in the application service
// Constructor injection:
private readonly IDistributedCache<<Entity>CacheItem> _<entity>Cache;
// GetOrAdd — recommended:
var item = await _<entity>Cache.GetOrAddAsync(
id.ToString(),
async () =>
{
var entity = await _<entity>Repository.GetAsync(id);
return new <Entity>CacheItem { Id = entity.Id, Name = entity.Name };
},
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30)
}
);
Step 4 — Invalidate the cache on changes
Show the lines to add in UpdateAsync and DeleteAsync:
await _<entity>Cache.RemoveAsync(id.ToString());
Step 5 — Redis setup (if requested)
[DependsOn] addition:
typeof(AbpCachingStackExchangeRedisModule)
ConfigureServices:
Configure<RedisCacheOptions>(options =>
{
options.Configuration = configuration["Redis:Configuration"];
});
appsettings.json:
{
"Redis": {
"Configuration": "127.0.0.1:6379"
}
}
Step 6 — Confirm rules
- Multi-tenancy isolation is automatic — no extra code needed
- Cache items must be plain serializable POCOs — not entities
- Always invalidate in UpdateAsync / DeleteAsync
- Use
[IgnoreMultiTenancy]only for data that is genuinely shared across all tenants