Token导航 LogoToken导航TokenDH.com
开发external-servicegithub未标认证来源可访问许可证需确认审计通过

implementing-database-caching实施数据库缓存

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

689

周安装

29

GitHub Stars

2,064

下载量

241
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:implementing-database-caching(实施数据库缓存)
来源仓库:https://github.com/jeremylongshore/claude-code-plugins-plus-skills
仓库路径:skills/implementing-database-caching
安装命令:
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill implementing-database-caching
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill implementing-database-caching

简介

implementing-database-caching 用于辅助数据库表结构、查询语句和迁移脚本编写,支持索引优化建议。

  • 适用于分析 schema、排查查询问题或生成数据维护方案等数据库任务。
  • 可编写 SQL 语句,但需明确数据库类型与连接环境,区分只读与分析操作。
  • 安装命令为 npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill implementing-database-caching。
  • 涉及删除或更新操作时应优先 dry-run 或事务保护,避免误操作。

SKILL.md

Database Cache Layer

Overview

Implement multi-tier caching strategies using Redis, application-level in-memory caches, and query result caching to reduce database load and improve read latency. This skill covers cache-aside, write-through, and write-behind patterns with proper invalidation strategies, TTL configuration, and cache stampede prevention.

Prerequisites

  • Redis server (6.x+) available or Docker for running docker run redis:7-alpine
  • redis-cli installed for cache inspection and debugging
  • Application framework with Redis client library (ioredis, redis-py, Jedis, go-redis)
  • Database query profiling data identifying read-heavy and slow queries
  • Understanding of data freshness requirements (how stale can cached data be)
  • Monitoring tools for cache hit rate and Redis memory usage

Instructions

  1. Profile database queries to identify caching candidates. Focus on queries that: execute more than 100 times per minute, take longer than 50ms, return data that changes less frequently than every 5 minutes, and produce results smaller than 1MB. Use pg_stat_statements or MySQL slow query log.
  2. Design the cache key schema with a consistent naming convention: service:entity:identifier:variant. Examples: app:user:12345:profile, app:products:category:electronics:page:1. Include a version prefix to enable bulk invalidation: v2:app:user:12345.
  3. Implement the cache-aside pattern for read-heavy data:

- Check Redis first: GET app:user:12345:profile - On cache miss: query database, then SET app:user:12345:profile <json> EX 3600 - On data update: DEL app:user:12345:profile to invalidate - Wrap in a helper function that abstracts cache-then-database logic

  1. Configure TTL values based on data change frequency:

- Static reference data (countries, categories): TTL 24 hours or longer - User profile data: TTL 15-60 minutes - Product listings: TTL 5-15 minutes - Session data: TTL matching session timeout - Real-time data (inventory counts, prices): TTL 30-60 seconds or skip caching

  1. Implement cache stampede prevention for high-traffic cache keys:

- Probabilistic early expiration: Refresh cache at TTL * 0.8 with probability 1 / concurrent_requests - Distributed lock: Use SET key:lock NX EX 5 to let one request refresh while others serve stale data - Stale-while-revalidate: Serve expired cache while refreshing in background

  1. Add application-level L1 cache using an in-memory LRU cache (Node.js: lru-cache, Python: cachetools, Java: Caffeine) for per-process caching of ultra-hot data. Set L1 TTL shorter than Redis TTL (e.g., 60 seconds L1, 5 minutes Redis).
  2. Configure Redis for production:

- Set maxmemory to 75% of available RAM - Set maxmemory-policy allkeys-lru for cache workloads - Enable save "" (disable RDB persistence) for pure cache use - Configure tcp-keepalive 60 and timeout 300

  1. Implement cache invalidation on data mutations. After INSERT, UPDATE, or DELETE operations, delete the corresponding cache key and any aggregate/list cache keys that include the modified data. Use Redis key patterns or tag-based invalidation for related keys.
  2. Add cache metrics instrumentation: track cache hit rate (hits / (hits + misses)), cache miss latency (time to populate from DB), Redis memory usage, eviction rate, and average key TTL remaining. Alert when hit rate drops below 80%.
  3. Test cache behavior under load: verify cache hit rate reaches 90%+ for targeted queries, confirm cache invalidation works correctly on updates, and measure end-to-end latency improvement compared to direct database queries.

Output

  • Redis configuration file with memory limits, eviction policy, and persistence settings
  • Cache wrapper module with get/set/invalidate functions and stampede prevention
  • Cache key schema documentation with naming conventions and TTL values per data type
  • Invalidation logic integrated with data access layer for automatic cache clearing on mutations
  • Monitoring dashboard queries for cache hit rate, memory usage, and eviction tracking

Error Handling

ErrorCauseSolution
Redis connection refusedRedis server down or network issueImplement circuit breaker pattern; fall through to database on cache unavailability; retry with exponential backoff
Cache stampede on popular key expirationMany concurrent requests hit cache miss simultaneouslyUse distributed locking or probabilistic early refresh; extend TTL with jitter (TTL + random(0, TTL*0.1))
Stale data served after database updateCache invalidation missed or delayedAudit invalidation paths; use publish/subscribe for cache invalidation events; reduce TTL for sensitive data
Redis out of memory (OOM)Cache size exceeds maxmemory settingEnable allkeys-lru eviction; reduce TTLs; audit large keys with redis-cli --bigkeys; increase maxmemory
Cache key collisionDifferent data stored under the same key patternInclude all discriminating parameters in the cache key; add content hash to key for variant detection

Examples

Caching product catalog for an e-commerce site: Product detail pages query 3 tables (products, categories, reviews_summary). Cache the assembled product JSON in Redis with TTL of 10 minutes. Cache hit rate reaches 95% since products change rarely. Category pages use list cache keys app:products:category:electronics:sort:price:page:1 with 5-minute TTL. On product update, invalidate both the product key and all category list keys containing that product.

User session caching with Redis: Store session data as Redis hashes (HSET session:abc123 userId 456 role admin lastAccess 1705341234). Set TTL to 30 minutes with sliding expiration on each access (EXPIRE session:abc123 1800). Session reads drop from 2ms (PostgreSQL) to 0.1ms (Redis), eliminating 50,000 database queries per minute.

API response caching with stale-while-revalidate: Dashboard endpoint takes 3 seconds to compute. Cache the response with 5-minute TTL. When TTL expires, the first request triggers an async background refresh while serving the stale cached response. Subsequent requests within the refresh window also receive the stale response. Dashboard always loads in under 5ms from the client perspective.

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.25%
按下载量换算85

Claude

28.99%
按下载量换算70

Cursor

18.18%
按下载量换算44

Gemini CLI

8.37%
按下载量换算20

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills