A regular website could easily cache the page’s information. The whole webpage is saved in the temporary folder so that it could be accessed faster the next time user visits the particular page. Unfortunately, this concept is only applied to HTML and other websites where the whole webpage is refreshed whenever something new is added.
Ajax on the other hand, refreshes only part of the page so the natural caching behavior is not applied as it does not detect any general changes on the webpage.
But there is actually a trick on how you can build a caching mechanism in your webpage. To understand this better, we go back to the basic operation of Ajax. Communication that enables changes on a specific part of the webpage requires the URL and the arrays which serve as a target for changes. You can use these elements as an array index that will serve as cached information. Regular caching procedures will follow – your computer will save the information in the temporary folder.
The next time you visit the webpage, instead of requesting the server for the page, you can compare the requested information with the cached data. Of course you have to add “if” function for the system to check the cached information first before proceeding to the server.
Problem comes in when too much information is requested. Even with a strong computer, it is only possible to store a small amount of information. When the temporary folder is “clogged” with temporary information from a particular website, the webpage and the whole browser will slow down and eventually stop functioning because of too much cached information.
To combat that problem an algorithm has to be established. You can use any function you want but while I was browsing through many options, I bumped into the Least Recently Used (LRU). This type of algorithm does exactly what it says in its name: it recognizes the least used cached and automatically deletes them as soon as new information comes in.
But another solution is to increase the cache size. Normally you will have at 5MB of cached information. Just like any HTML based websites you can, easily increase this through a command. The downside of this is your website might run slower that expected because of too much cached information.
Your website will spend too much time checking if there are any matches in the cached section. If you cannot run away from a bigger cache size, consider doubling the link of each cache. Every cache will have forward links as well as backward links. Through this technique which is also called the doubly linked list, you can minimize the temporary stored information.
Caching in Ajax is possible. We had to struggle a little bit in this situation because of browser problem especially on IE but we have found a simple and efficient solution for that. Now, we just have to control the influx of temporary information so that our Ajax based websites will work as efficiently planned.


1 Trackback(s)