-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
58 lines (49 loc) · 1.4 KB
/
option.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cache
import (
"github.com/sirupsen/logrus"
)
// Option is the type of constructor options for New(...).
type Option func(c *Cache)
// WithStorage configures a cache client with a cache.Storage to store
// data
func WithStorage(storage ...Storage) Option {
return func(c *Cache) {
if len(storage) == 0 {
return
}
c.storage[PriorityHigh] = storage
}
}
// WithHighPriorityStorage configures a cache instance with a priority
// cache.Storage to store data
func WithHighPriorityStorage(storage ...Storage) Option {
return withPriorityStorage(PriorityHigh, storage...)
}
// WithMediumPriorityStorage configures a cache instance with a medium
// cache.Storage to store data
func WithMediumPriorityStorage(storage ...Storage) Option {
return withPriorityStorage(PriorityMedium, storage...)
}
func withPriorityStorage(priority Priority, storage ...Storage) Option {
return func(c *Cache) {
c.storage[priority] = append(c.storage[priority], storage...)
}
}
// WithDebug configures a cache instance with debug flag on
func WithDebug() Option {
return func(c *Cache) {
c.logger.SetLevel(logrus.DebugLevel)
}
}
// WithTagger configures a cache instance with custom cache.Tagger
func WithTagger(tagger Tagger) Option {
return func(c *Cache) {
c.tagger = tagger
}
}
// WithNamespace configures a cache instance with namespace.
func WithNamespace(ns string) Option {
return func(c *Cache) {
c.ns = ns
}
}