/
2008-11-20-new-jquery-plugin-object-cache.html
38 lines (27 loc) · 1.49 KB
/
2008-11-20-new-jquery-plugin-object-cache.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
layout: post
title: 'New jQuery plugin: Object Cache'
tags:
- caching
- javascript
- jquery
- plugin
date: 2008-11-20 18-54-56
---
<p>Inspired by <a href="http://benjaminsterling.com" target="_blank">Benjamin Sterling</a>'s <a href="http://benjaminsterling.com/better-jquery-code-1/" target="_blank">"Better jQuery Code"</a> article I decided to develop a simple plugin to make his first point (<em>Caching</em>) easier... nothing fancy, just a few methods, but you will hopefully find it useful.</p>
<p>Its objective is to let you store a jQuery object with a simple key in a global cache, so that you can access the same object easily, without having to write the same selection, filtering or traversing code (i.e: $("#main < p") or $("#main").children(".selected").eq(0)).</p>
<h2>Here is how it works:</h2>
<pre class='prettyprint'>
// Store in cache - Returns current object
$("#mainNav").cache("main_navigation");
// Retrieve from cache - Returns cached object
$$("main_navigation"); // or jQueryCache("main_navigation");
// Remove from cache
$$.remove("main_navigation");
// Clear Cache
$$.clear();
// Load jQueryCache with noConflict to avoid overriding window.$$
$$.noConflict();
</pre>
<p>There is a lot of room for improvement, which will be done depending on the feedback I get, so feel free to contact me with any ideas or corrections you might come up with.</p>
<p><a href="http://plugins.jquery.com/project/object-cache" target="_blank">You can get the Jquery Object Cache plugin here</a>.</p>