Documentation
¶
Overview ¶
Package gcache provides caching interceptors for gRPC clients.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrKey = "error"
ErrKey specifies the error key for logging.
Functions ¶
Types ¶
type Interceptor ¶
type Interceptor struct {
// contains filtered or unexported fields
}
Interceptor is a cache interceptor. It looks over the ETag header and caches the response ONLY if the ETag is present.
func NewInterceptor ¶
func NewInterceptor(opts ...Option) *Interceptor
NewInterceptor makes a new Interceptor.
func (*Interceptor) UnaryClientInterceptor ¶
func (c *Interceptor) UnaryClientInterceptor() grpc.UnaryClientInterceptor
UnaryClientInterceptor returns a new unary client interceptor that caches the response.
func (*Interceptor) UnaryServerInterceptor ¶
func (c *Interceptor) UnaryServerInterceptor() grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptor that caches the response. It doesn't use ETag header, but Cache-Control header.
type LRUBackend ¶
type LRUBackend interface {
Add(key string, value Entry) (evicted bool)
Get(key string) (value Entry, ok bool)
Remove(key string) (present bool)
}
LRUBackend specifies interface to be implemented by hashicorp LRU cache backends.
type Option ¶
type Option func(*Interceptor)
Option is a configuration option.
func WithFilter ¶
WithFilter sets the filter that is used to match the methods that must be cached.
type RawBytesCodec ¶
type RawBytesCodec struct{}
RawBytesCodec sets the received bytes as-is to the target, whether it is a byte slice or a proto.Message. For proto.Message, it uses proto.Marshal and proto.Unmarshal.
type RedisOption ¶
type RedisOption func(*redisStore)
RedisOption is a configuration option.
func WithRedisLogger ¶
func WithRedisLogger(l *slog.Logger) RedisOption
WithRedisLogger sets the logger.
func WithRedisSkipLocalCache ¶
func WithRedisSkipLocalCache(skipLocalCache bool) RedisOption
WithRedisSkipLocalCache sets the skipLocalCache.
type Store ¶
type Store interface {
Get(ctx context.Context, key string) (e Entry, ok bool)
Set(ctx context.Context, key string, e Entry)
Remove(ctx context.Context, key string)
}
Store is a cache store.
func NewLRU ¶
func NewLRU(backend LRUBackend) Store
NewLRU wraps hashicorp/golang-lru/v2 cache implementations to be used as interceptor's store.
func NewRedis ¶
func NewRedis(backend *rediscache.Cache, opts ...RedisOption) Store
NewRedis returns a new redisStore cache store.