PART IV
Appendix C: AjaxTCR Library Reference 621
MethodDescriptionExampleadd(key,
value)Adds any value (any valid JavaScript data item) to the internal library cache at the string specified by key. Normally not directly invoked, though provided for advanced developer use; typical action is performed via the setting of thecacheResponseproperty in a request’s option object.AjaxTCR.comm.cache.add("rollcall",["Murray","Jermaine","Bret"]);AjaxTCR.comm.cache.add("country", "New Zealand");AjaxTCR.comm.cache.add("/sic.php",myXhr.responseText);clear()Clears all items from the cache.AjaxTCR.comm.cache.clear(); /* cleaning up */get(key)Retrieves the value at the passed key.AjaxTCR.comm.cache.get("country"); /* would return "New Zealand" */getAll()Returns the entire cache, which is an array of cache objects each containing the following properties:key,value,
lastAccessed,added, andtotalAccessed. Useful for manual
manipulation of the cache.var dumped = AjaxTCR.comm.cache.getAll();getSize()Returns the length of the cache.alert(AjaxTCR.comm.cache.getSize());remove(key)Removes the cached object associated with the key string passed.AjaxTCR.comm.cache.remove("/sic.php");setOptions(options)Passes an object of options to override the cache defaults. The object passed may contain the following properties:sizeofthe cache, as in number of entries allowed (default 100);algorithm(defaultLRU) to maintain the cachebased upon string values “LRU”(Least Recently Used) [Default], “FIFO” (First In First Out), and“LFU”: (Least Frequently Used);andexpires, which is the defaultnumber of minutes to expire an item (default 60).AjaxTCR.comm.cache.setOptions({size: 10, algorithm: "FIFO", expires: 2});AjaxTCR.comm.cache.setOptions({algorithm: "LFU" });TABLEC-4Methods for Handling Response Cache