Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method to clear dataset cache or make it context configurable (page or DOM element) #221

Closed
jeffmax opened this issue Apr 30, 2013 · 28 comments
Assignees
Milestone

Comments

@jeffmax
Copy link
Contributor

jeffmax commented Apr 30, 2013

A method for clearing the dataset cache or changing its context from page level to element level would be useful. For larger/long running applications, the page-level cache behavior can be unexpected and undesirable. Providing away to override this, or at least programmatically clear the cache on demand would be helpful. For more justification please see my comment at the bottom of issue #41.

@brianmhunt
Copy link

Incidentally, a pull like the one proposed for #95 (pull #220) would permit circumventing the Typeahead.js cache; you could manage your own cache, e.g. with a request management library like amplify.js or model/collection/view manager like Backbone.js.

@andriijas
Copy link

I am using mixed sources for my single page app, some backbone collections and some raw prefetch urls. So would still be helpful to notify typehead to clear the cache somehow.

@ghost ghost assigned jharding Jul 10, 2013
@andriijas
Copy link

Please consider this :) Thanks!

@ukilon-okta
Copy link

+1 on cache flush.

In a feature I am working on we add resources from the backend, and once resource is added, you can't added again. the way typeahead caches it is impossible to exclude it from the result set.

I ended up cheating and setting a random name + a random string in the URI to work around it, but ideally clearing the cache would be cleaner.

@gesellix
Copy link

+1
I would also prefer to programmatically clear the Dataset cache.

@ghost
Copy link

ghost commented Sep 6, 2013

+1

2 similar comments
@kipwilliams
Copy link

+1

@digz6666
Copy link

+1

@atronchi
Copy link

This should probably be done by default in the destroy method, since if we destroy a typeahead, we generally don't care about the backing store any longer so it shouldn't be kept in memory.

@Crysis21
Copy link

+1

6 similar comments
@iloveitaly
Copy link

👍

@d0nd3r3k
Copy link

d0nd3r3k commented Oct 3, 2013

+1

@richadlr
Copy link

richadlr commented Oct 6, 2013

+1

@Nelrann
Copy link

Nelrann commented Oct 7, 2013

+1

@vukoje
Copy link

vukoje commented Oct 7, 2013

+1

@tommasop
Copy link

+1

@stevenlhunter
Copy link

+1

Unpleasantly surprised when I figured out that typeahead( 'destroy'), doesn't do this, "destroy" to me implies razed to the ground, plant salt, etc.

@JFickel
Copy link

JFickel commented Oct 27, 2013

+1

1 similar comment
@GrahamCampbell
Copy link

+1

@tellex
Copy link

tellex commented Nov 7, 2013

I have the same problem with destroy... to quick fix simple add line cache = new Array(); to the destroy function ....
i'm tryng to create a cacheRefresh function to modify typeahead cache without destroy all.... it's all in the cache variable inside typehead... maybe i will finish it today...

@tellex
Copy link

tellex commented Nov 12, 2013

https://github.com/tellex/typeahead.js/commit/7a10abf0fd958883b2b009622caa977b15d26994

Added refreshCache method. So if you have multiple datasets binded to a typehead and u need to change a particular dataset value simple call $(".input-box").typeahead("refreshCache",[{name:Dataset1, url: "New URL"}]); -> Is important to always add "[]" because refreshCache expects an array of objects. This function will find all dataset cached to the typeahead and walk trought the array to find the matching dataset.name then it will check which attributes values changed and replace the new ones , refresh the associated cache object, and reinitialize the typeahead.
If u wish to add an dataset to the already existent datasets simple add the property AddDataset to the passed object. example $(".input-box").typeahead("refreshCache",[{name:NewDataSetName, local: etcetc, AddDataset: true}])

I added an new event called typeahead:dropdownOpened the reason behind this is that if add a new refreshCache dataset i will reinitialize the typeahead and destroy previously DOM created object ... so if u have binded an event to a element in the displayed suggestions Box it will be lost.... the solution to this:
Once you created the typeahead add
$(".input-box").on("typeahead:dropdownOpened",function(){
$('.special-suggestion-button').bind('click',function(event){ alert("Custom function"); event.stopImmediatePropagation() } );
});
I do this because if u do $('.tt-dropdown-menu').on('suggestionsRendered',function()).... and call new method refreshCache i will reinitialize the whole DOM object and destroy .tt-dropdown-menu so... the binded "on" will be lost...

Hope you enjoy the new function , sorry for my bad grammar my native languaje is spanish....

Greetings from argentina!!!

@igal-getrailo
Copy link

I'm sorry, but how can I destroy all the caches? I tried
$('#search').typeahead('refreshCache', [{name:'items', remote:'/mysurl?q=%QUERY'}])

but it throws an error: one of local, prefetch, or remote is required.

isn't there an easier way to just refresh all the caches?

what is the default expiration of the cache?

@jharding
Copy link
Contributor

FYI in v0.10 there won't be a dataset cache so this should no longer be an issue.

@igal-getrailo
Copy link

I'm a little confused by the versioning here. I am using 0.9.3 which in my understanding is far greater than 0.10 ? or by 0.10 you mean 0.10.1?

@jharding
Copy link
Contributor

I mean v0.10.0 which is greater than v0.9.3.

@pepijnolivier
Copy link

I found that the following line clears the cache:
localStorage.clear()

This of course clears everything out of the localstorage. But since I didn't have anything interesting in there, this was enough for me.

@jharding
Copy link
Contributor

jharding commented Feb 2, 2014

v0.10.0 has been released so this should no longer be an issue.

@jharding jharding closed this as completed Feb 2, 2014
@dustingraham
Copy link

I'm still having an issue with this and I've got v0.10.1, but I suspect the issue is in the bloodhound repo.

Edit: To clarify, the issue that is no longer an issue, is no longer an issue. (I think that issue is the one where a dataset was page level, there are now options to have different datasets, sweet.) The issue I was having was the difficulty of clearing the cache, which this issue also touches on. My solution was to set prefetch: { ttl: 1 } since each time my users return to the page, there is a high likelyhood that the cache is stale due to the nature of our dashboard and changing data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests