77 "fmt"
88 "time"
99
10- "github.com/jellydator/ttlcache/v3"
1110 "github.com/redis/go-redis/v9"
1211 "go.uber.org/zap"
1312
@@ -16,52 +15,24 @@ import (
1615
1716const (
1817 catalogRedisTimeout = time .Second * 1
19-
20- // this is just how long we are keeping sandbox in local cache so we don't have to query redis every time
21- // we don't want to go too high because then sbx can be run on different orchestrator, and we will not be able to find it
22- catalogRedisLocalCacheTtl = time .Millisecond * 500
2318)
2419
25- type SandboxCache interface {
26- Get (key string , opts ... ttlcache.Option [string , * SandboxInfo ]) * ttlcache.Item [string , * SandboxInfo ]
27- Set (key string , value * SandboxInfo , ttl time.Duration ) * ttlcache.Item [string , * SandboxInfo ]
28- Delete (key string )
29- Stop ()
30- }
31-
3220type RedisSandboxCatalog struct {
3321 redisClient redis.UniversalClient
34- cache SandboxCache
3522}
3623
3724var _ SandboxesCatalog = (* RedisSandboxCatalog )(nil )
3825
39- func NewReadThroughSandboxCache () * ttlcache.Cache [string , * SandboxInfo ] {
40- cache := ttlcache .New (
41- ttlcache.WithTTL [string , * SandboxInfo ](catalogRedisLocalCacheTtl ),
42- ttlcache .WithDisableTouchOnHit [string , * SandboxInfo ](),
43- )
44- go cache .Start ()
45-
46- return cache
47- }
48-
49- func NewRedisSandboxCatalog (redisClient redis.UniversalClient , cache SandboxCache ) * RedisSandboxCatalog {
26+ func NewRedisSandboxCatalog (redisClient redis.UniversalClient ) * RedisSandboxCatalog {
5027 return & RedisSandboxCatalog {
5128 redisClient : redisClient ,
52- cache : cache ,
5329 }
5430}
5531
5632func (c * RedisSandboxCatalog ) GetSandbox (ctx context.Context , sandboxID string ) (* SandboxInfo , error ) {
5733 spanCtx , span := tracer .Start (ctx , "sandbox-catalog-get" )
5834 defer span .End ()
5935
60- sandboxInfo := c .cache .Get (sandboxID )
61- if sandboxInfo != nil {
62- return sandboxInfo .Value (), nil
63- }
64-
6536 ctx , ctxCancel := context .WithTimeout (spanCtx , catalogRedisTimeout )
6637 defer ctxCancel ()
6738
@@ -80,8 +51,6 @@ func (c *RedisSandboxCatalog) GetSandbox(ctx context.Context, sandboxID string)
8051 return nil , fmt .Errorf ("failed to unmarshal sandbox info: %w" , err )
8152 }
8253
83- c .cache .Set (sandboxID , info , catalogRedisLocalCacheTtl )
84-
8554 return info , nil
8655}
8756
@@ -104,8 +73,6 @@ func (c *RedisSandboxCatalog) StoreSandbox(ctx context.Context, sandboxID string
10473 return fmt .Errorf ("failed to store sandbox info in redis: %w" , status .Err ())
10574 }
10675
107- c .cache .Set (sandboxID , sandboxInfo , catalogRedisLocalCacheTtl )
108-
10976 return nil
11077}
11178
@@ -134,7 +101,6 @@ func (c *RedisSandboxCatalog) DeleteSandbox(ctx context.Context, sandboxID strin
134101 }
135102
136103 c .redisClient .Del (ctx , c .getCatalogKey (sandboxID ))
137- c .cache .Delete (sandboxID )
138104
139105 return nil
140106}
@@ -144,7 +110,5 @@ func (c *RedisSandboxCatalog) getCatalogKey(sandboxID string) string {
144110}
145111
146112func (c * RedisSandboxCatalog ) Close (_ context.Context ) error {
147- c .cache .Stop ()
148-
149113 return nil
150114}
0 commit comments