DEV Community

siddharth hariramani
siddharth hariramani

Posted on

Redis Caching — How I Cut API Response from 2s to 0.1s

Redis Caching Strategy

My site PlayTeraBox.online resolves Terabox video links. Without caching: 1.8s. With Redis: 0.1s.

Implementation

import redis, json
r = redis.Redis(host='localhost', port=6379)

def get_cached(key, fetch_fn, ttl=3600):
    cached = r.get(key)
    if cached: return json.loads(cached)
    result = fetch_fn()
    r.setex(key, ttl, json.dumps(result))
    return result
Enter fullscreen mode Exit fullscreen mode

Results

  • Response time: 1.8s → 0.1s
  • Cache hit rate: 85%
  • Server CPU: 78% → 12%

Built for PlayTeraBox.online

Top comments (0)