skills/dotnet/patterns/caching-strategy/SKILL.md
Define explicit caching strategies for different data access patterns and consistency requirements in .NET applications. Use when: - Implementing caching for frequently accessed data - Optimizing read-heavy workloads - Reducing database load with appropriate caching - Handling cache invalidation strategies - Building systems with varying cache requirements Triggers: "caching strategy", "cache", "redis", "cache invalidation", "TTL", "cache warming"
npx skillsauth add yeeehaooo/WorkSpace caching-strategyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Define explicit caching strategies for different data access patterns and consistency requirements.
Applies to:
// Application Layer
public interface ICachingStrategy
{
Task<T?> GetAsync<T>(string key, CancellationToken ct = default);
Task SetAsync<T>(string key, T value, TimeSpan? ttl = null, CancellationToken ct = default);
Task InvalidateAsync(string key, CancellationToken ct = default);
Task InvalidateByPatternAsync(string pattern, CancellationToken ct = default);
}
// Infrastructure Layer
public class RedisCachingStrategy : ICachingStrategy
{
private readonly IDatabase _redis;
private readonly string _keyPrefix;
public async Task<T?> GetAsync<T>(string key, CancellationToken ct = default)
{
var fullKey = $"{_keyPrefix}:{key}";
var value = await _redis.StringGetAsync(fullKey);
return value.HasValue ? JsonSerializer.Deserialize<T>(value!) : default;
}
public async Task SetAsync<T>(string key, T value, TimeSpan? ttl = null, CancellationToken ct = default)
{
var fullKey = $"{_keyPrefix}:{key}";
var json = JsonSerializer.Serialize(value);
await _redis.StringSetAsync(fullKey, json, ttl);
}
public async Task InvalidateAsync(string key, CancellationToken ct = default)
{
var fullKey = $"{_keyPrefix}:{key}";
await _redis.KeyDeleteAsync(fullKey);
}
}
// Usage in Query Handler
public class GetUserHandler : IQueryHandler<GetUserQuery, UserDto>
{
private readonly IUserRepository _userRepo;
private readonly ICachingStrategy _cache;
public async Task<UserDto> Handle(GetUserQuery query, CancellationToken ct)
{
var cacheKey = $"user:{query.UserId}";
var cached = await _cache.GetAsync<UserDto>(cacheKey, ct);
if (cached != null)
return cached;
var user = await _userRepo.GetByIdAsync(query.UserId, ct);
var dto = MapToDto(user);
await _cache.SetAsync(cacheKey, dto, TimeSpan.FromMinutes(10), ct);
return dto;
}
}
development
Create reusable .NET atomic capability code snippets that can be directly copied and pasted. Use when: - Creating single-purpose code snippets - Building reusable code templates - Implementing atomic technical capabilities - Creating copy-pasteable code blocks - Building snippet library for common patterns Triggers: "create snippet", "code snippet", "reusable snippet", "atomic snippet", "copy-paste code"
development
Create Docker Compose configuration for containerized .NET application development and deployment. Use when: - Containerizing .NET applications - Setting up local development environment with dependencies - Creating multi-container setups (API + DB + Redis) - Defining service dependencies and networking - Building docker-compose.yml for development or production Triggers: "docker compose", "containerize", "multi-container", "docker-compose.yml", "docker setup"
tools
Create adapter structure for integrating third-party APIs in Clean Architecture applications. Use when: - Integrating external APIs or services - Creating HTTP client adapters for third-party services - Implementing API integration with error handling - Setting up adapter pattern for external dependencies - Building resilient external service integrations Triggers: "api adapter", "third-party api", "external service", "http client adapter", "api integration"
development
Enterprise backend structure built on Clean Architecture, DDD, CQRS, and Vertical Slice API Design with Dapper-first persistence. Use when: - Creating new enterprise backend projects - Implementing Clean Architecture with DDD and CQRS - Building vertical slice API endpoints - Using Dapper as primary persistence mechanism - Organizing modules by UseCase-driven and Model-driven separation Triggers: "dmis structure", "clean architecture", "enterprise backend", "DDD CQRS", "vertical slice", "dapper"