Ajax on Autocomplete does not fire again, if previously fired I am using Drupal 6, and question is regarding autocomplete.
As a part of performance, I am caching the results of AJAX calls, so that if the same values are passed, we dont have to fire ajax call again, and should get the result instantly.

Scenario
I have 2 autocomplete fields, one coming from Drupal taxonomy module, for tags and the other is a custom autocomplete field added via form alter, fetching some other information from custom table.

While I was checking on the Drupal default autocomplete field for tags, I saw that the if I insert the same text, the ajax is not fired. 
Like I insert "I", I get some values, change it to "j", I get some other values, If I change it back to "I", NO ajax is fired.
However, for my custom autocomplete field, i am able to see 3 ajax calls.

Can someone please put some light as to how drupal does it, so that even i can implement the same on our custom field as well.
I am using drupal 6, but if you are aware of how it is done in Drupal 7 as well, it would be a great help.
The basic idea behind this is to simply cache the AJAX response of an autocomplete query keyed by the query string itself. Eg.

q = 'I',
cache miss
cache['I'] =&gt; [ 'India', 'Indonesia', 'Italy', 'Iceland' ]
[ 'India', 'Indonesia', 'Italy', 'Iceland' ]

q = 'In'
cache miss
cache['In'] =&gt; [ 'India', 'Indonesia' ]

q = 'I'
cache hit
[ 'India', 'Indonesia', 'Italy', 'Iceland' ]


If you inspect misc/autocomplete.js in Drupal 7, you'd notice that there is a Drupal.ACDB (Autocomplete Database for those curious) object. What's more interesting is the search() method implementation in the same object. You'd notice that given a query string, first the in-memory cache object is looked up first before an AJAX request is made. This is something that you might want to emulate too.