Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions gache.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ var hashSeed = maphash.MakeSeed()
func New[V any](opts ...Option[V]) Gache[V] {
g := new(gache[V])
for _, opt := range append([]Option[V]{
WithDefaultExpiration[V](30 * time.Second),
WithMaxKeyLength[V](256),
}, opts...) {
opt(g)
Expand Down
4 changes: 4 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func WithExpiredHookFunc[V any](f func(ctx context.Context, key string, v V)) Op
}
}

// WithMaxKeyLength sets the maximum number of bytes used from each key when
// computing the shard ID. Keys up to 32 bytes use maphash for hashing; longer
// keys use xxh3. A value of 0 means the full key is always used. The default
// is 256 bytes.
func WithMaxKeyLength[V any](kl uint64) Option[V] {
return func(g *gache[V]) error {
g.maxKeyLength = kl
Expand Down