-
Notifications
You must be signed in to change notification settings - Fork 336
/
context.go
34 lines (25 loc) · 956 Bytes
/
context.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
package content
import "context"
type contextKey string
var useContentCacheContextKey contextKey = "use-content-cache"
var useListCacheContextKey contextKey = "use-list-cache"
// UsingContentCache returns a derived context that causes content manager to use cache.
func UsingContentCache(ctx context.Context, enabled bool) context.Context {
return context.WithValue(ctx, useContentCacheContextKey, enabled)
}
// UsingListCache returns a derived context that causes content manager to use cache.
func UsingListCache(ctx context.Context, enabled bool) context.Context {
return context.WithValue(ctx, useListCacheContextKey, enabled)
}
func shouldUseContentCache(ctx context.Context) bool {
if enabled, ok := ctx.Value(useContentCacheContextKey).(bool); ok {
return enabled
}
return true
}
func shouldUseListCache(ctx context.Context) bool {
if enabled, ok := ctx.Value(useListCacheContextKey).(bool); ok {
return enabled
}
return true
}