mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
29 lines
1.0 KiB
Go
29 lines
1.0 KiB
Go
package contracts
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
// ErrCacheMiss is returned when an item is not found in the cache.
|
|
var ErrCacheMiss = errors.New("contracts/cache: key not found")
|
|
|
|
// CacheService defines the contract for multi-layer cache operations (RAM L1 + Redis L2 + Pub/Sub invalidation).
|
|
type CacheService interface {
|
|
// Get retrieves an item from cache into target. Returns ErrCacheMiss if not found.
|
|
Get(ctx context.Context, key string, target any) error
|
|
|
|
// Set stores an item into cache with a specified time-to-live duration.
|
|
Set(ctx context.Context, key string, value any, ttl time.Duration) error
|
|
|
|
// Delete evicts a key from local and remote cache tiers and broadcasts invalidation.
|
|
Delete(ctx context.Context, key string) error
|
|
|
|
// GetOrSet retrieves an item from cache, or calls loader to populate and return if missing.
|
|
GetOrSet(ctx context.Context, key string, target any, ttl time.Duration, loader func() (any, error)) error
|
|
|
|
// Invalidate is a semantic alias for Delete.
|
|
Invalidate(ctx context.Context, key string) error
|
|
}
|