mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
- 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).
30 lines
753 B
Go
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)
|
|
}
|