-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
43 lines (37 loc) · 1.17 KB
/
Copy pathoptions.go
File metadata and controls
43 lines (37 loc) · 1.17 KB
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
package bmemcache
import "time"
// Option defines a function that configures cache options.
type Option interface {
// Apply sets the option on the provided configuration.
Apply(o *option)
}
// option holds configuration settings for the cache.
type option struct {
// AutoCleanup enables the background cleanup of expired cache entries.
AutoCleanup bool
// AutoCleanupInterval defines the interval between automatic cleanup operations.
AutoCleanupInterval time.Duration
// CacheKeySeparator is the string used to separate keys when generating the cache key.
CacheKeySeparator string
}
// WithAutoCleanUp enables auto-cleanup and sets the cleanup interval.
//
// Parameters:
// - interval: The time interval between automatic cleanup operations.
//
// Returns:
// - An Option to be passed to the New() function.
func WithAutoCleanUp(interval time.Duration) Option {
return &withAutoCleanUp{duration: interval}
}
type withAutoCleanUp struct {
duration time.Duration
}
// Apply sets the auto-cleanup options.
func (w *withAutoCleanUp) Apply(o *option) {
o.AutoCleanup = true
o.AutoCleanupInterval = w.duration
if w.duration == 0 {
o.AutoCleanupInterval = time.Minute
}
}