Skip to content

Commit 36d03ce

Browse files
authored
Avoid blocking if promotables channel is full.
In rare situation it is possible to have `promotables` channel full. In such condition, the `Get` function will be blocked because it calls `promote` function. `Get` function being blocked defeats the purpose of fast cache response and hence may impact the application code in unexpected manner. In this commit, the `promote` function is modified to use non-blocking channel send construct.
1 parent b779edb commit 36d03ce

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cache.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ func (c *Cache) bucket(key string) *bucket {
206206
}
207207

208208
func (c *Cache) promote(item *Item) {
209-
c.promotables <- item
209+
select {
210+
case c.promotables <- item:
211+
default:
212+
}
213+
210214
}
211215

212216
func (c *Cache) worker() {

0 commit comments

Comments
 (0)