Documentation
¶
Index ¶
- func New(opts ...Option) func(gas.ConfigProvider, gas.Logger) *Service
- type Config
- type Option
- type Service
- func (s *Service) Close() error
- func (s *Service) Delete(_ context.Context, key string) error
- func (s *Service) Exists(_ context.Context, key string) (bool, error)
- func (s *Service) Get(_ context.Context, key string) ([]byte, error)
- func (s *Service) Init() error
- func (s *Service) Name() string
- func (s *Service) Set(_ context.Context, key string, value []byte, ttl time.Duration) error
- type Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
env.WithGasEnv
Cache Settings
}
Config holds in-memory cache settings.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with sensible defaults.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is an in-memory cache implementing gas.Service and gas.CacheProvider. It uses a simple map with optional background cleanup of expired entries.
func (*Service) Get ¶
Get returns the value for the given key, or cache.ErrKeyNotFound if the key does not exist or has expired.
func (*Service) Init ¶
Init validates the configuration and starts the background cleanup goroutine.
func (*Service) Set ¶
Set stores a value with the given TTL. If ttl is 0, the configured DefaultTTL is used. If DefaultTTL is also 0, the entry never expires. When MaxEntries is reached and a new key is inserted, the oldest expired entry is evicted first; if none are expired, the set is rejected with an error.
type Settings ¶
type Settings struct {
// MaxEntries is the maximum number of entries in the cache.
// 0 means unlimited.
MaxEntries int
// CleanupInterval is how often expired entries are evicted.
// 0 disables background cleanup.
CleanupInterval time.Duration
// DefaultTTL is the default time-to-live for entries when Set is
// called with ttl == 0. A value of 0 means entries never expire.
DefaultTTL time.Duration
}
Settings represents the configuration for the in-memory cache.