jQuery Object Cache plugin
by Jack K
The jQuery Object Cache plugin showed up on my radar a few days ago. It's a neat little plugin that would come in handy if you've got some jQuery selectors that you find you're re-using often on a page and would like to toss them into a cache instead of refetching them each time you need them:
http://www.decodeuri.com/2008/11/20/new-jquery-plugin-object-cache
I could see using this on smaller projects, but more than likely we'd end up using it on larger projects where a page has a lot of dynamic activity going on in the browser. Usually we just set a local var using something like:
var $listItems = $('#list li');
and then we reuse the $listItems var, but Object Cache would allow us to stuff the results of the selector into a cache, so we wouldn't have to grab them from the DOM again.
3 comments
You are not 'stuffing' anything anuwhere else but in the array of the cache. And most importantly, you are stuffing references to dom nodes. Same as jQery does.
It is therefore of no use to reuse the $listitems (as above) because anything can happen to the actual dom nodes being referenced. they can also be removed. all of them or just some.
And another jQ instance which is just the reference to the original one, will happily proceed working on removed nodes, for a while. untill erros start flying arround.
Therefore: do not cache and do not reuse REFERENCES.
Because actual objects can change or dissapear.
12/09/08 11:25:51 am, 