-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathoptions.go
More file actions
38 lines (31 loc) · 786 Bytes
/
options.go
File metadata and controls
38 lines (31 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package lru
const (
// DefaultCacity is the default cache capacity
DefaultCapacity = 10000
)
// CacheOption configurs a lru cache.
type CacheOption interface {
apply(*options)
}
// funcCacheOption wraps a function to implement the CacheOption interface.
type funcCacheOption func(o *options)
func (f funcCacheOption) apply(o *options) {
f(o)
}
// WithCapacity configures how many items can be stored before old items begin
// to be deleted.
func WithCapacity(capacity int) CacheOption {
return funcCacheOption(func(o *options) {
o.capacity = capacity
})
}
// options for a cache instance.
type options struct {
capacity int
}
// defaultOptions returns options with default values set.
func defaultOptions() *options {
return &options{
capacity: DefaultCapacity,
}
}