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
Results
- Response time: 1.8s → 0.1s
- Cache hit rate: 85%
- Server CPU: 78% → 12%
Built for PlayTeraBox.online
Top comments (0)