tercul-backend/internal/platform/cache/graphql_adapter.go
google-labs-jules[bot] 6d40b4c686 feat: add security middleware, graphql apq, and improved linting
- Add RateLimit, RequestValidation, and CORS middleware.
- Configure middleware chain in API server.
- Implement Redis cache for GraphQL Automatic Persisted Queries.
- Add .golangci.yml and fix linting issues (shadowing, timeouts).
2025-11-30 21:17:43 +00:00

30 lines
753 B
Go

// Package cache provides cache implementations and adapters.
package cache
import (
"context"
"time"
)
// GraphQLCacheAdapter adapts the RedisCache to the graphql.Cache[string] interface
type GraphQLCacheAdapter struct {
RedisCache *RedisCache
}
// Get looks up a key in the cache
func (a *GraphQLCacheAdapter) Get(ctx context.Context, key string) (string, bool) {
// gqlgen APQ stores strings.
var s string
err := a.RedisCache.Get(ctx, key, &s)
if err != nil {
return "", false
}
return s, true
}
// Add adds a key to the cache
func (a *GraphQLCacheAdapter) Add(ctx context.Context, key, value string) {
// Use default TTL of 24 hours for APQ. The interface does not provide TTL.
_ = a.RedisCache.Set(ctx, key, value, 24*time.Hour)
}