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

Comment from: DBJDBJ [Visitor] · http://dbj.org
" ... 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."

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.



03/24/09 @ 08:47
I want to start my first blog, what blog platform do you use and recommend for me ?
04/08/10 @ 04:49
I think what you mentioned in your post interest to say the least. Recently i seen reviews about this on http://www.rapidsloth.com/Flower-Girls-Wallpapers.html and alot of people praise it.
04/30/10 @ 06:23

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)