Skip to content

Conversation

@buger
Copy link
Member

@buger buger commented Jan 30, 2026

Summary

Adds a new cache_hit field to the Tyk Gateway access logs that indicates whether a response was served from the cache.

  • Adds CacheHit context key for passing cache status through request context
  • Sets cache_hit=true in Redis cache middleware when serving cached responses
  • Includes cache_hit field in all access log entries (defaults to false for non-cached responses)
  • Adds access log recording for cached responses (previously missing)
  • Adds table-driven unit tests for the new functionality

Test plan

  • Unit tests pass for the accesslog package (go test ./internal/httputil/accesslog/...)
  • Code compiles without errors (go build ./ctx/... ./gateway/... ./internal/httputil/accesslog/...)
  • Go vet passes (go vet ./gateway/...)
  • Integration tests with Redis should verify:
    • Access logs contain cache_hit=true when response is served from cache
    • Access logs contain cache_hit=false when response is from upstream

Related Issues

🤖 Generated with Claude Code

This change adds a new `cache_hit` field to the access logs that indicates
whether a response was served from the cache.

Changes:
- Add CacheHit context key in ctx/ctx.go
- Add ctxSetCacheHit/ctxGetCacheHit functions in gateway/api.go
- Set cache_hit flag to true in mw_redis_cache.go when serving from cache
- Add WithCacheHit method to accesslog.Record
- Update RecordAccessLog to include cache_hit field
- Add RecordAccessLog call for cached responses in mw_redis_cache.go
- Add table-driven unit tests for cache_hit field

The cache_hit field will be:
- true: when the response is served from the Redis cache
- false: when the response is fetched from the upstream service

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants