Skip to content

Commit

Permalink
fix: evict keys remotely as well (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: viney-shih <[email protected]>
  • Loading branch information
VineyAT and viney-shih authored May 26, 2022
1 parent a219085 commit 453f7ed
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ func (c *cache) load(ctx context.Context, cfg *config, keys ...string) ([]Value,
WithOnCostAddFunc(c.onLCCostAdd),
WithOnCostEvictFunc(c.onLCCostEvict),
)

c.evictRemoteKeyBytes(ctx, m)
}
}

Expand All @@ -325,6 +327,8 @@ func (c *cache) refill(ctx context.Context, cfg *config, keyBytes map[string][]b
); err != nil {
return nil
}

c.evictRemoteKeyBytes(ctx, keyBytes)
}

return nil
Expand All @@ -348,6 +352,15 @@ func (c *cache) del(ctx context.Context, cfg *config, keys ...string) error {
return nil
}

func (c *cache) evictRemoteKeyBytes(ctx context.Context, keyBytes map[string][]byte) error {
keys := []string{}
for k := range keyBytes {
keys = append(keys, k)
}

return c.publishEvictEvents(ctx, keys...)
}

func (c *cache) publishEvictEvents(ctx context.Context, keys ...string) error {
if c.pubsub == nil {
// do nothing
Expand Down

0 comments on commit 453f7ed

Please sign in to comment.