Documentation
¶
Index ¶
- func Key(r *http.Request, scope []string) string
- func KeyWithCustomHeaders(r *http.Request, scope []string, additionalHeaders []string) string
- type Config
- type Entry
- type MemoryStore
- func (s *MemoryStore) Clear() error
- func (s *MemoryStore) Close() error
- func (s *MemoryStore) Delete(key string)
- func (s *MemoryStore) Get(key string) (*Entry, bool)
- func (s *MemoryStore) Purge(tag string) error
- func (s *MemoryStore) Set(key string, entry *Entry, ttl time.Duration)
- func (s *MemoryStore) SetWithPolicy(key string, entry *Entry, policy *alaye.TTLPolicy, defaultTTL time.Duration)
- type RedisStore
- func (s *RedisStore) Clear() error
- func (s *RedisStore) Close() error
- func (s *RedisStore) Delete(key string)
- func (s *RedisStore) Get(key string) (*Entry, bool)
- func (s *RedisStore) Purge(tag string) error
- func (s *RedisStore) Set(key string, entry *Entry, ttl time.Duration)
- func (s *RedisStore) SetWithPolicy(key string, entry *Entry, policy *alaye.TTLPolicy, defaultTTL time.Duration)
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Key ¶
Key builds a cache key from the request, incorporating standard Vary headers and any additional scope specifiers.
Every field is followed by a "|" delimiter to prevent boundary-shifting collisions (e.g. Path="/api/useri" Query="d=123" must not hash identically to Path="/api/user" Query="id=123").
func KeyWithCustomHeaders ¶
KeyWithCustomHeaders builds a cache key including arbitrary request headers, useful for CDN Vary expansion (e.g. CF-IPCountry, X-Tenant).
Every field is followed by a "|" delimiter to prevent boundary-shifting collisions. See Key() for the full rationale.
Types ¶
type Config ¶
type Config struct {
Driver string
DefaultTTL time.Duration
MaxItems int
// MaxCacheableSize is the maximum response body size (bytes) that will be
// stored. Responses larger than this are passed through without caching.
// 0 means use the built-in default (def.CacheMaxBodySize).
MaxCacheableSize int64
Redis *alaye.RedisCache
Policy *alaye.TTLPolicy
}
type Entry ¶
type Entry struct {
Body []byte
Headers http.Header
Status int
StoredAt time.Time
CreatedAt time.Time
TTL time.Duration
VaryHeaders map[string]string
ContentType string
// SurrogateTags holds CDN cache tags (e.g. "product:42", "category:books").
// Used by PurgeByTag to selectively invalidate groups of cached responses.
// Populated from the upstream Surrogate-Key or Cache-Tag response header.
SurrogateTags []string
}
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
func NewMemoryStore ¶
func NewMemoryStore(cfg *Config) (*MemoryStore, error)
func (*MemoryStore) Clear ¶
func (s *MemoryStore) Clear() error
func (*MemoryStore) Close ¶
func (s *MemoryStore) Close() error
func (*MemoryStore) Delete ¶
func (s *MemoryStore) Delete(key string)
func (*MemoryStore) Purge ¶ added in v0.1.2
func (s *MemoryStore) Purge(tag string) error
PurgeByTag removes all entries whose SurrogateTags contain the given tag.
func (*MemoryStore) SetWithPolicy ¶
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
func NewRedisStore ¶
func NewRedisStore(cfg *Config) (*RedisStore, error)
func (*RedisStore) Clear ¶
func (s *RedisStore) Clear() error
func (*RedisStore) Close ¶
func (s *RedisStore) Close() error
func (*RedisStore) Delete ¶
func (s *RedisStore) Delete(key string)
func (*RedisStore) Purge ¶ added in v0.1.2
func (s *RedisStore) Purge(tag string) error
PurgeByTag removes all entries indexed under the given surrogate tag. Uses the tag index maintained in Set to avoid a full SCAN.
func (*RedisStore) SetWithPolicy ¶
type Store ¶
type Store interface {
Get(key string) (*Entry, bool)
Set(key string, entry *Entry, ttl time.Duration)
SetWithPolicy(key string, entry *Entry, policy *alaye.TTLPolicy, defaultTTL time.Duration)
Delete(key string)
Clear() error
Close() error
// Purge removes all cached entries that carry the given surrogate tag.
Purge(tag string) error
}
Store is the cache backend interface. PurgeByTag is required for CDN surrogate-key invalidation.