diff options
| -rw-r--r-- | lib/utils.coffee | 11 | ||||
| -rw-r--r-- | pages/vomnibar.coffee | 5 | 
2 files changed, 14 insertions, 2 deletions
| diff --git a/lib/utils.coffee b/lib/utils.coffee index 354d82f6..1c24a40f 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -236,6 +236,17 @@ class SimpleCache      else        null +  clear: -> +    @rotate() +    @rotate() + +  # Because of the timer, we can't just let these caches go out of scope and have the garbage collector +  # harvest them.  Whenever they may fall out of use, we need to remove the timer. @rotate() can be used to +  # restart the cache. +  suspend: -> +    clearTimeout @timer if @timer? +    @timer = null +    # Set value, and return that value.  If value is null, then delete key.    set: (key, value = null) ->      if value? diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index de1e6452..76e276a1 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -210,6 +210,7 @@ class BackgroundCompleter    constructor: (@name) ->      @port = chrome.runtime.connect name: "completions"      @messageId = null +    @cache ?= new SimpleCache 1000 * 60 * 5      @reset()      @port.onMessage.addListener (msg) => @@ -259,8 +260,8 @@ class BackgroundCompleter      @port.postMessage name: @name, handler: "refresh"    reset: -> -    # We only cache results for the duration of a single vomnibar activation. -    @cache = new SimpleCache 1000 * 60 * 5 +    # We only cache results for the duration of a single vomnibar activation, so clear the cache now. +    @cache.clear()      @mostRecentQuery = null    cancel: -> | 
