buildr/modules/state/state_cache.go

32 lines
575 B
Go
Raw Permalink Normal View History

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
2023-06-22 16:06:56 +00:00
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)
}