Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func (c *Client[T]) GetOrFetch(ctx context.Context, key string, fetchFn FetchFn[
// T - The type stored in the cache.
func GetOrFetch[V, T any](ctx context.Context, c *Client[T], key string, fetchFn FetchFn[V]) (V, error) {
res, err := getFetch[V, T](ctx, c, key, fetchFn)
if err != nil {
var zero V
return zero, err
}
return unwrap[V](res, err)
}

Expand Down Expand Up @@ -227,5 +231,9 @@ func (c *Client[T]) GetOrFetchBatch(ctx context.Context, ids []string, keyFn Key

func GetOrFetchBatch[V, T any](ctx context.Context, c *Client[T], ids []string, keyFn KeyFn, fetchFn BatchFetchFn[V]) (map[string]V, error) {
res, err := getFetchBatch[V, T](ctx, c, ids, keyFn, fetchFn)
if err != nil {
var zero map[string]V
return zero, err
}
return unwrapBatch[V](res, err)
}
Loading