🚧 Scaffold stuff
This commit is contained in:
parent
21ffd33be7
commit
a73435601c
6 changed files with 212 additions and 0 deletions
31
cache.go
Normal file
31
cache.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package ezcache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ErrInvalidFetcher is returned by Cache.SetFetcher if the fetcher is invalid.
|
||||
// This is probably only going to happen if it's nil.
|
||||
var ErrInvalidFetcher = errors.New("invalid fetcher")
|
||||
|
||||
// ErrInvalidDuration is returned by Cache.SetExpiry if the duration is invalid.
|
||||
// This is usually if it is <= 0.
|
||||
var ErrInvalidDuration = errors.New("invalid duration")
|
||||
|
||||
type Fetcher[K comparable, V any] func(K) (V, error)
|
||||
|
||||
// Cache represents a Cache for values.
|
||||
type Cache[K comparable, V any] interface {
|
||||
// Get will fetch the value for key. If in the cache, it will fetch the cached value.
|
||||
// If not in the cache, it will use the Fetcher.
|
||||
// It may return [ErrInvalidFetcher], but if an error is returned, it's probably returned by the
|
||||
// [Fetcher] itself.
|
||||
Get(key K) (V, error)
|
||||
|
||||
// SetFetcher sets the fetcher for this [Cache].
|
||||
SetFetcher(f Fetcher[K, V]) error
|
||||
|
||||
// SetExpiry sets the expiry for this [Cache].
|
||||
SetExpiry(d time.Duration) error
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue