Skip to content

Commit

Permalink
[patch] export updater & store types (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnkamalesh authored Oct 28, 2024
1 parent d8c4b00 commit 95dcc8f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
ErrValidation = errors.New("invalid")
)

type store[K comparable, T any] interface {
type Store[K comparable, T any] interface {
Add(key K, value *Payload[T]) (evicted bool)
Get(key K) (value *Payload[T], found bool)
Remove(key K) (present bool)
Expand All @@ -43,8 +43,8 @@ type Config[K comparable, T any] struct {

// UpdaterTimeout is the context time out for when the updater function is called
UpdaterTimeout time.Duration
Updater updater[K, T]
Store store[K, T]
Updater Updater[K, T]
Store Store[K, T]

// ErrWatcher is called when there's any error when trying to update cache
ErrWatcher ErrOnUpdate
Expand Down Expand Up @@ -106,7 +106,7 @@ type Payload[T any] struct {
payload T
}

type updater[K comparable, T any] func(ctx context.Context, key K) (T, error)
type Updater[K comparable, T any] func(ctx context.Context, key K) (T, error)

type Tuple[K comparable, T any] struct {
Key K
Expand All @@ -121,7 +121,7 @@ type Value[T any] struct {
type Cache[K comparable, T any] struct {
isDisabled bool
disableServeStale bool
store store[K, T]
store Store[K, T]
cacheAge time.Duration

deleteQ chan<- K
Expand All @@ -130,7 +130,7 @@ type Cache[K comparable, T any] struct {
// threshold is the duration within which if the cache is about to expire, it is eligible to be updated
threshold time.Duration
updateQ chan<- K
updater updater[K, T]
updater Updater[K, T]
updaterTimeout time.Duration
// updateInProgress is used to handle update debounce
updateInProgress *sync.Map
Expand Down Expand Up @@ -263,7 +263,7 @@ func (ch *Cache[K, T]) BulkAdd(tuples []Tuple[K, T]) (evicted []bool) {
return evicted
}

func DefaultStore[K comparable, T any](lrusize int) (store[K, T], error) {
func DefaultStore[K comparable, T any](lrusize int) (Store[K, T], error) {
lCache, err := lru.New[K, *Payload[T]](int(lrusize))
if err != nil {
return nil, fmt.Errorf("failed initializing LRU cache: %w", err)
Expand Down

0 comments on commit 95dcc8f

Please sign in to comment.