buildr/modules/state/state_cache.go
Peter 1261932bdc
All checks were successful
continuous-integration/drone/push Build is passing
refactor: apply golangci-lint findings
2023-06-22 19:16:00 +02:00

32 lines
575 B
Go

package state
import (
"context"
"time"
)
func NewStateCache(ttl time.Duration, store Store) *StateCache {
return &StateCache{
TTL: ttl,
Store: store,
}
}
var _ Cache = (*StateCache)(nil)
type StateCache struct {
Store Store
TTL time.Duration
}
func (s *StateCache) Set(ctx context.Context, key Key, state []byte) error {
return s.Store.Set(ctx, key, state, WithTTL(s.TTL))
}
func (s *StateCache) Get(ctx context.Context, key Key) (state []byte, meta Metadata, err error) {
if s == nil {
return nil, Metadata{}, nil
}
return s.Store.Get(ctx, key)
}