LRU Cache for JS

May 31, 2007 on 10:12 pm | In ajax |

Two years ago, I built an Ajax interface for a message board. The design called for all navigation to occur within the context of one page. Message lists updated on a polling interval, and users could open threads, read messages within threads, or search by topic or user within that page. All of the content was loaded via XHR, some user specific formatting was applied, and the results were shown within a DIV.

Following what I have just now decided to call “The First Principle of Performance Optimization” — reduce network requests as much as possible — I put together a simple LRU Cache to store message bodies and other post-formatting replies. Knowing that users frequently come back to a given message or thread, this saved the network round trip as well as the formatting step to provide a snappier end user perceived performance.

The technique worked well, but my caching scheme was pretty unimpressive and unpolished: there were no priority levels and the expiration scheme was spartan. That’s why I was excited this week to see a much more fully realized LRU Cache developed by Monsur Hossain and released under an MIT license. It provides priorities for objects in the cache, two expiration schemes, and a callback function executed on object expiry, all with a sane and clean API.

If you’re in the market for a JS cache, this looks like a great choice.

(Update: somehow I forgot to give this a subject. Looked naked :-))

1 Comment »

RSS feed for comments on this post. TrackBack URI

  1. [...] the responsiveness of your application. Using a technique similar to what we discussed with the JS LRU cache a while back, they created a mechanism for preloading messages behind the scenes as the application loads. When [...]

    Pingback by Ajax Performance » Catching up on a slew of pending posts — August 12, 2007 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^