Bambi
Bambi

Reputation: 1

Typeahead 0.9.3 - Clear local suggestions cache

I'm using Twitter Typeahead 0.9.3 on remote mode which works pretty nicely except for one part, I need to clear suggestion cache at some point. It is not stored in localStorage nor DOM which makes it difficult to find.

I found out the remote part of typeahead initialization has a cache option which I set to false so it adds a timestamp to queries. Unfortunately, it doesn't apply if I type 'a', another query, then 'a' again, it will not make a new request but fetch it from cache.

Here's my initialization:

$('.typeahead).typeahead({
    name: 'typeahead_' + fieldId,
    limit: 10,
    remote: {
        url: '/foo/query/%QUERY',
        cache: false
    },
    template: template,
    engine: Hogan
});

What am I doing wrong ? Or how can I can force Typeahead to refetch even if the query has already been typed before ?

Thanks for your help!

Upvotes: 0

Views: 2031

Answers (2)

Mehul Koradiya
Mehul Koradiya

Reputation: 129

$('#item').typeahead('destroy');

  $('#item').typeahead({
    local: items
  });

Upvotes: 1

tknv
tknv

Reputation: 562

I think if using bloodhound together, it will be. Please see sample site below.
https://twitter.github.io/typeahead.js/examples/
There is remote smaple, like a you are trying. And if you add below among bloodhound and typeahead, the prefetch cache will be clear.

i.e.

...
bestPictures.clearPrefetchCache();  
bestPictures.initialize();  

$('#remote .typeahead').typeahead(null, {
  name: 'best-pictures',
  display: 'value',
  source: bestPictures
});

Upvotes: 0

Related Questions