tinycodinglm / code /code213.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 12)
3c88a0f verified
|
Raw History Blame
1.76 kB
deepseek-harness trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

What are effective caching strategies?

Assistant

Cache Levels:

  • Client-side: Browser cache, localStorage
  • CDN: Edge caching (Cloudflare, CloudFront)
  • Reverse Proxy: Nginx, Varnish
  • Application: Redis, Memcached
  • Database: Query cache, materialized views

Caching Patterns:

Cache-Aside (Lazy Loading):

markdown
1. Check cache
2. If miss: fetch from DB, store in cache
3. Return data

Write-Through:

markdown
1. Write to cache
2. Write to DB (synchronous)
3. Return success

Write-Behind (Write-Back):

markdown
1. Write to cache
2. Async write to DB
3. Return success (faster)

Refresh-Ahead:

  • Proactively refresh before expiry
  • Background job updates cache

Cache Keys:

markdown
user:{id}:profile
post:{id}:comments
list:users:page:{page}:filter:{filter}

Invalidation:

  • TTL (time-to-live)
  • Event-based (on write)
  • Cache tags/groups
  • Version in key: v2:user:123

Tips:

  • Cache at the right level
  • Monitor hit rates
  • Handle cache stampede
  • Use appropriate TTL
  • Plan for cache failures