jquery.suggestions: Support caching results to save http requests
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 21 May 2014 01:18:32 +0000 (03:18 +0200)
committerKrinkle <krinklemail@gmail.com>
Sat, 7 Jun 2014 08:13:36 +0000 (08:13 +0000)
commit96c65cf811865497ea2bc3ed0abd261765e4fcf6
treec54fc5e45fcadf2c450b08877c0cdd11b30f647d
parenta6c074a9444c8feaf71d5e0063e4318f1e676bb4
jquery.suggestions: Support caching results to save http requests

When typing the same thing multiple times, or when pressing backspace
(thus reverting to an earlier known value), or otherwise ending
up with the same value, we can re-use the data we already used.

Doesn't happen in the basic case of typing one thing without mistakes
and selecting a results, but happens more than one might think.

People are often impatient, or even use the suggestions as their
search results and based on that might try something else and then
go back (e.g. try "Foo", find a good result but not ideal, try "Bar",
even worse, go back to "Foo", select "Foo thing").

During this, requests for "B", "Ba", "F", "Fo" and "Foo" would be
fired more than once (B-Ba when backspacing, F-Fo-Foo when typing it
the second time, or simply using ctrl-Z a couple times).

By default cache disabled (individual users of this plugin have
to opt-in). When enabled it defaults to an expiry of 1 minute.

Also:
* Cleaned up computing of $textbox.val(), it was being computed several
  times in a synchronous block.
* Simplified bool cast from foo ? true : false, to !!foo.

Bug: 65581
Change-Id: Ib10c65f6ab31773b7f517b2f9c3cc7c7b93c6d39
resources/src/jquery/jquery.suggestions.js