@@ -11,12 +11,12 @@ import (
11
11
"github.com/jellydator/ttlcache/v3"
12
12
)
13
13
14
- type LruCache struct {
14
+ type lruCache struct {
15
15
mc metrics.Client
16
16
c * ttlcache.Cache [string , workflow.WorkflowExecutor ]
17
17
}
18
18
19
- func NewWorkflowExecutorLRUCache (mc metrics.Client , size int , expiration time.Duration ) workflow. ExecutorCache {
19
+ func NewWorkflowExecutorLRUCache (mc metrics.Client , size int , expiration time.Duration ) * lruCache {
20
20
c := ttlcache .New (
21
21
ttlcache.WithCapacity [string , workflow.WorkflowExecutor ](uint64 (size )),
22
22
ttlcache.WithTTL [string , workflow.WorkflowExecutor ](expiration ),
@@ -37,13 +37,13 @@ func NewWorkflowExecutorLRUCache(mc metrics.Client, size int, expiration time.Du
37
37
mc .Counter (metrickeys .WorkflowInstanceCacheEviction , metrics.Tags {metrickeys .EvictionReason : reason }, 1 )
38
38
})
39
39
40
- return & LruCache {
40
+ return & lruCache {
41
41
mc : mc ,
42
42
c : c ,
43
43
}
44
44
}
45
45
46
- func (lc * LruCache ) Get (ctx context.Context , instance * core.WorkflowInstance ) (workflow.WorkflowExecutor , bool , error ) {
46
+ func (lc * lruCache ) Get (ctx context.Context , instance * core.WorkflowInstance ) (workflow.WorkflowExecutor , bool , error ) {
47
47
e := lc .c .Get (getKey (instance ))
48
48
if e != nil {
49
49
return e .Value (), true , nil
@@ -52,23 +52,23 @@ func (lc *LruCache) Get(ctx context.Context, instance *core.WorkflowInstance) (w
52
52
return nil , false , nil
53
53
}
54
54
55
- func (lc * LruCache ) Store (ctx context.Context , instance * core.WorkflowInstance , executor workflow.WorkflowExecutor ) error {
55
+ func (lc * lruCache ) Store (ctx context.Context , instance * core.WorkflowInstance , executor workflow.WorkflowExecutor ) error {
56
56
lc .c .Set (getKey (instance ), executor , ttlcache .DefaultTTL )
57
57
58
58
lc .mc .Gauge (metrickeys .WorkflowInstanceCacheSize , metrics.Tags {}, int64 (lc .c .Len ()))
59
59
60
60
return nil
61
61
}
62
62
63
- func (lc * LruCache ) Evict (ctx context.Context , instance * core.WorkflowInstance ) error {
63
+ func (lc * lruCache ) Evict (ctx context.Context , instance * core.WorkflowInstance ) error {
64
64
lc .c .Delete (getKey (instance ))
65
65
66
66
lc .mc .Gauge (metrickeys .WorkflowInstanceCacheSize , metrics.Tags {}, int64 (lc .c .Len ()))
67
67
68
68
return nil
69
69
}
70
70
71
- func (lc * LruCache ) StartEviction (ctx context.Context ) {
71
+ func (lc * lruCache ) StartEviction (ctx context.Context ) {
72
72
go lc .c .Start ()
73
73
74
74
<- ctx .Done ()
0 commit comments