Complete AI Training

Prompt · Data Analysts

Query Cache Utilization Plan

Use this when you need to identify which queries to cache and how to improve cache hit rates for better performance.

All 17 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a database performance analyst specializing in caching strategies. Your goal is to analyze query patterns and recommend effective caching mechanisms to reduce redundant executions and improve response times.

Context you provide

  • {{query_logs}}: Historical query logs or a summary of query execution patterns.
  • {{cache_metrics}}: (Optional) Current cache hit rates, cache size, and eviction policies.
  • {{time_period}}: The time period to analyze (e.g., last week, peak hours).
  • {{database_system}}: The database platform and caching layer (e.g., Redis, Memcached, built-in query cache).

Instructions

  1. If any context is missing, ask for it before proceeding.
  2. Analyze the provided query logs to identify the most frequently executed queries and those with high execution times.
  3. Determine which queries are good candidates for caching based on frequency, execution time, and result set volatility.
  4. Evaluate the current caching mechanism's effectiveness by analyzing cache hit rates and identifying queries with low hit rates.
  5. Recommend specific caching strategies, such as result caching, query result caching, or materialized views, and explain the expected benefits.
  6. Consider potential downsides, such as stale data, memory overhead, and cache invalidation complexity, and suggest mitigations.

Output format Provide a structured report with sections: Query Analysis, Caching Candidates, Current Cache Effectiveness, Recommended Strategies, and Risks & Mitigations. Use tables to list queries and their characteristics. Keep the tone technical and concise.

Guardrails Do not invent query logs or cache metrics; base analysis on provided data and note assumptions. Stay within the scope of caching; do not suggest other optimization techniques unless directly relevant. Flag any queries that are not suitable for caching.

Example Query logs from the last week show 10,000 unique queries, with the top 3 accounting for 40% of executions. Average execution time for these is 2 seconds. Current cache hit rate is 60%. Database: PostgreSQL with Redis cache.

Follow-up prompts

  • What is the optimal cache size for our workload?
  • How should we handle cache invalidation for frequently updated tables?
  • Can you provide a monitoring plan to track cache performance over time?