Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(store Store, opts ...Option) grpc.UnaryClientInterceptor
UnaryClientInterceptor is a convenience that creates a CacheInterceptor internally and returns the interceptor function directly.
Types ¶
type CacheInterceptor ¶
type CacheInterceptor struct {
// contains filtered or unexported fields
}
CacheInterceptor caches gRPC unary responses. Create with NewCacheInterceptor, then pass UnaryClientInterceptor() to grpc.WithChainUnaryInterceptor.
func NewCacheInterceptor ¶
func NewCacheInterceptor(store Store, opts ...Option) *CacheInterceptor
NewCacheInterceptor creates a cache interceptor with the given store and options.
func (*CacheInterceptor) Stats ¶
func (c *CacheInterceptor) Stats() Stats
Stats returns cache hit/miss counters (atomic reads).
func (*CacheInterceptor) UnaryClientInterceptor ¶
func (c *CacheInterceptor) UnaryClientInterceptor() grpc.UnaryClientInterceptor
UnaryClientInterceptor returns the interceptor for use with grpc.WithChainUnaryInterceptor.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is a bounded in-memory Store with TTL.
func NewMemoryStore ¶
func NewMemoryStore(maxSize int) *MemoryStore
NewMemoryStore creates a memory store. maxSize <= 0 defaults to 256.
func (*MemoryStore) Delete ¶
func (m *MemoryStore) Delete(key string)
func (*MemoryStore) Len ¶
func (m *MemoryStore) Len() int
Len returns the current number of entries.
type Option ¶
type Option func(*config)
Option configures the cache interceptor.
func WithDefaultTTL ¶
WithDefaultTTL sets the cache TTL (default 1 min).
func WithFilter ¶
WithFilter adds a custom predicate checked before cache lookup. Return true = eligible; false = bypass cache.
func WithKeyFunc ¶
WithKeyFunc overrides the default cache key generation (method + SHA-256 of proto-marshalled request).
func WithMethods ¶
WithMethods restricts caching to the listed full method names (e.g. "/pkg.Service/Method"). Nil or empty = cache all unary methods.
func WithSingleFlight ¶
func WithSingleFlight() Option
WithSingleFlight deduplicates concurrent cache-miss invocations for the same key so all concurrent callers share the result of a single RPC.