<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Abhi&#039;s Weblog &#187; Caching</title>
	<atom:link href="http://abhinavsingh.com/blog/tag/caching/feed/" rel="self" type="application/rss+xml" />
	<link>http://abhinavsingh.com/blog</link>
	<description>PHP, Memcached, XMPP and Web Development</description>
	<lastBuildDate>Mon, 27 Feb 2012 09:12:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQL Query Cache, WP-Cache, APC, Memcache &#8211; What to choose</title>
		<link>http://abhinavsingh.com/blog/2009/01/mysql-query-cache-wp-cache-apc-memcache-what-to-choose/</link>
		<comments>http://abhinavsingh.com/blog/2009/01/mysql-query-cache-wp-cache-apc-memcache-what-to-choose/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 18:18:58 +0000</pubDate>
		<dc:creator>Abhinav Singh</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scalability]]></category>
		<category><![CDATA[APC]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[Memcache]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Opcode]]></category>
		<category><![CDATA[Query Cache]]></category>
		<category><![CDATA[WP-Cache]]></category>

		<guid isPermaLink="false">http://abhinavsingh.com/blog/?p=153</guid>
		<description><![CDATA[Hello Cache Freaks, Ever since I changed my job (from Business Intelligence to Web development) and started working with my present employer, I have had a chance to work on a lot of scalable projects. From making my project to scale from 20 Million PV&#8217;s to 100 Million PV&#8217;s to development of an internal tool, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2009%2F01%2Fmysql-query-cache-wp-cache-apc-memcache-what-to-choose%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2009%2F01%2Fmysql-query-cache-wp-cache-apc-memcache-what-to-choose%2F&amp;source=imoracle&amp;style=normal&amp;service=bit.ly&amp;service_api=R_f027b5a79a20a49b713f16282f1e0857&amp;hashtags=APC,Caching,Memcache,MySQL,Opcode,PHP,Query+Cache,WP-Cache&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hello Cache Freaks,</p>
<p>Ever since I changed my job (from Business Intelligence to Web development) and started working with my present employer, I have had a chance to work on a lot of scalable projects. From making my project to scale from 20 Million PV&#8217;s to 100 Million PV&#8217;s to development of an internal tool, the answer to all scalable applications have been caching.</p>
<p>There are a lot of caching techniques which are being employed by sites worldwide.</p>
<ol>
<li><strong>WP-Cache</strong> used in wordpress &#8211; a file system based caching mechanism</li>
<li><strong>APC Cache</strong> &#8211; an opcode based caching system</li>
<li><strong>Memcache</strong> &#8211; an in memory caching system</li>
<li><strong>Query Cache</strong> &#8211; caching mechanism employed in MySQL</li>
</ol>
<p>Here in this post I would like to pen down my experiences while working with all the caching mechanism. Their pros and cons. What things you need to take care while working with them and every little tit bit which comes to my mind while writing this post.</p>
<p><strong style="font-size:18px;"><u>Query Cache &#8211; inbuilt cache mechanism in MySQL</u></strong><br />
Query cache is an inbuilt cache mechanism for MySQL. Basically when you fire a query against a MySQL database, it goes through a lot of core modules. e.g. Connection Manager, Thread Manager, Connection Thread, User Authentication Module, Parse Module, Command Dispatcher, Optimizer Module, Table Manager, Query Cache Module and blah blah. Discussing these modules is out of scope of this blog post. The only module we are interested here is Query Cache Module.</p>
<p>Suppose I fire a query:<br />
$query = &#8220;Select * from users&#8221;;</p>
<p>MySQL fetches it for the first time from the database and caches the result for further similar query. Next time when you fire a similar query, it picks the result from the cache and deliver it back to you.</p>
<p>However, there are a few <u>drawbacks</u> with Query Cache:</p>
<ul>
<li>If there is a new entry in the <em>users</em> table, the cache is cleared.</li>
<li>Secondly, even if the result of your query is cached, MySQL has to go through a number of core modules before it give back the cached result to you.</li>
<li>Thirdly, even if your results are caches, you need to connect to your MySQL database, which generally have a bottleneck with number of connections allowed.</li>
</ul>
<p>One thing which you should take care while replying on Query Cache is that, your query must not have any parameter which is random or changes quite often. For e.g. If you wish to fetch url&#8217;s of 100 photo from the database, and then you want to present them in a random fashion every time, you might be tempted to use <strong>rand()</strong> somewhere in your MySQL queries. However by using rand() you ensure that the query is never returned from cache, since rand() parameter always makes the query look different.</p>
<p>Similarly, If you have a case where you need to show data not older than 15 days, and by mistake you also include the seconds parameter in your SQL query, then the query will never return from cache.</p>
<p>Hence for a scalable site, with 100 Million PV&#8217;s you can&#8217;t really survive with a simple query cache provided by MySQL database.</p>
<p><strong style="font-size:18px;"><u>WP-Cache &#8211; Caching mechanism for WordPress blogs</u></strong><br />
WP-Cache is a file system based caching mechanism i.e. it caches your blog posts in form of simple text files which are saved on your file system. You can have a look at these cached files by visiting <em><u>wp-content/cache</u></em> folder inside your blog directory. Generally you will find two set of files for a single blog post. One .html and another .meta file.</p>
<p><u><em>.html file</em></u> generally contains the static html content for your blog post. Once published, the blog post content is static, hence instead of fetching it&#8217;s data from the database, WP-Cache serves it from the <em>cache</em> directory.</p>
<p><u><em>.meta file</em></u> contains serialized information such as Last Modified, Content-Type, URI which WP-Cache uses to maintain cache expiry on your blog.</p>
<p>WP-Cache works really well, however if the traffic starts increasing on your blog, then the bottleneck will be maximum number of child processes which apache can create (<em>For starters you can think, each user connecting to your blog as one apache process, hence there is a restriction on number of users who can connect to your blog at a particular time</em>). In such case the solution can be either to have multiple front end servers with a load balancer to distribute the traffic among front end servers, or to have a better cache solution such as a memory based caching mechanism (e.g. Memcache). Also since memory read is always faster than file read, you must go for a memory based cache system.</p>
<p><strong style="font-size:18px;"><u>APC Cache &#8211; An opcode based cache for PHP</u></strong><br />
APC stands for Alternative PHP Cache. In one of my previous post <a target="_blank" href="http://abhinavsingh.com/blog/2008/11/how-does-php-echos-a-hello-world-behind-the-scene/">How does PHP echo’s a “Hello World”? &#8211; Behind the scene</a>, I talk about how PHP churns out &#8220;Hello World&#8221; for you.</p>
<p>PHP takes your code through various steps:</p>
<ol>
<li>Scanning &#8211; The human readable source code is turned into tokens.</li>
<li>Parsing &#8211; Groups of tokens are collected into simple, meaningful expressions.</li>
<li>Compilation &#8211; Expressions are translated into instruction (opcodes)</li>
<li>Execution &#8211; Opcode stacks are processed (one opcode at a time) to perform the scripted tasks.</li>
</ol>
<p>Opcode caches let the ZEND engine perform the first three of these steps, then store that compiled form (opcodes) so that the next time a given script is used, it can use the stored version without having to redo those steps only to come to the same result.</p>
<p>However the problem with APC cache is that it is not a distributed cache system. By distributed cache I mean, if you have 3 frontend server then you need to have a copy of this opcode on all the three fronend server. <del datetime="2009-01-16T14:17:16+00:00">Also like WP-Cache APC is again a file system driven cache system, which is not the optimal solution.</del> Also with APC cache, PHP still has to go through the last step as described above.</p>
<p><strong style="font-size:18px;"><u>Memcache &#8211; In memory based cache mechanism</u></strong><br />
Memcache is the solution when you talk about million PV&#8217;s on your site. <em>It is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.</em></p>
<p>For starters, Memcache is not PHP, nor Python or any other thing as you may think. It&#8217;s a deamon which runs in the background on your server. Your code connects to it and cache query results, JS, CSS and other cachable data in the server&#8217;s memory (RAM). Since its an in-memory caching system, it is faster than any of the discussed caching system above. However it is unreliable and unsecure but then there are ways to tackle this unreliable and unsecure nature of memcache.</p>
<p>Memcache is unreliable because it resides in your system memory. So an event like system reboot or power failure will result in loss of all your cache. Also memcache provides no mechanism to take backup of your caches. Hence once lost, you need to programmatically warmup your caches.</p>
<p>Memcache is unsecure because it doesn&#8217;t require any authentication mechanism. There is no username or password with which your code connects to it. (Hence it is super fast, unlike Query cache which has to go through auth module even if the query result is cached). It usually runs at port 11211 on your server and if not taken care, anyone can telnet to port 11211 on your server and steal your caches.</p>
<p>Below are the steps which are being followed on a memcache enabled website:</p>
<ol>
<li>User enter your site&#8217;s url in his browser, say http://localhost</li>
<li>There are about 6 queries which drives your opening page</li>
<li>Lets assume one of the query for this page is <em>$query = &#8220;SELECT photo_url from photos LIMIT 0,10&#8243;</em></li>
<li>When the user visit http://localhost, your code will first connect to memcache deamon on port 11211</li>
<li>If memcache deamon is running, it checks if the result of this query are already cached. Generally data is cached in memcache as (key,value) pair</li>
<li>Since this is the first visit on your site, ofcourse there is no query being cached till now. Hence your code now connect to your MySQL database and fetched the resultset. Something like this probably. <em>$resultset = mysql_query($query);</em></li>
<li>After successfully fetching the resultset, your code will cache this resultset in memcache. The code connects to memcache deamon and saves this (key,value) pair in memory, where $key = md5($query) and $value = serialize($resultset)</li>
<li>After caching the (key,value) pair, your code returns back the fetched resultset to the frontpage where it is being displayed to the user</li>
<li>Similarly all the 6 queries which drives your front page are being cached one by one</li>
<li>Now the next time when another user visit this page i.e. http://localhost, your code will first see if $key = md5($query) is already present in cache. It will find the $key being cached, fetches the serialized resultset from memory, unserialize it and throws back to the front page where it is displayed as intended</li>
<li>While caching (key,value) pair you also have a provision to specify a TTL (time to live) after which memcache will automatically expire your cached result</li>
<li>Suppose you specifies a TTL = 15 Minutes for all the above queries and now a visitor visit http://localhost after 30 minutes</li>
<li>Your code will again first connect to memcache deamon and check if $key = md5($query) is present in cache. Memcache deamon will see that this $key is present but it has expired. It will return a result saying $key is not cached and internally flushes out $key. Your code then again connect to MySQL database, fetches the resultset and cache back the results in memcache for further use</li>
</ol>
<p>I will leave you with a presentation on memcache which I gave sometime back at office. I hope it will help you gain more understanding of memcache.</p>
<p><center></p>
<div style="width:425px;text-align:left" id="__ss_917157"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/imoracle/memcache-presentation?type=powerpoint" title="Memcache">Memcache</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=memcache-1231956637654098-1&#038;stripped_title=memcache-presentation" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=memcache-1231956637654098-1&#038;stripped_title=memcache-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View SlideShare <a style="text-decoration:underline;" href="http://www.slideshare.net/imoracle/memcache-presentation?type=powerpoint" title="View Memcache on SlideShare">presentation</a> or <a style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own. (tags: <a style="text-decoration:underline;" href="http://slideshare.net/tag/caching">caching</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/memcache">memcache</a>)</div>
</div>
<p></center></p>
<p>In my next posts, I will be covering a few code samples and use cases of memcache which you wouldn&#8217;t even heard of. If you liked the post don&#8217;t forget to promote it on social networking sites and do subscribe to my blog. <img src='http://abhinavsingh.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div id="paidTxtLinkAds">Learn PHP with our <a href="http://www.testking.org/642-901.htm">testking 642-901</a> web development course. Download <a href="http://www.testking.org/642-812.htm">testking 642-812</a> php material and reviews, articles and <a href="http://www.testking.org/70-640.htm">testking 70-640</a> video tutorials to get in depth knowledge.</div>
<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/api.tweetmeme.com\/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2009%2F01%2Fmysql-query-cache-wp-cache-apc-memcache-what-to-choose%2F","http:\/\/www.slideshare.net\/imoracle\/memcache-presentation?type=powerpoint","http:\/\/www.slideshare.net\/imoracle\/memcache-presentation?type=powerpoint","http:\/\/www.slideshare.net\/upload?type=powerpoint","http:\/\/slideshare.net\/tag\/caching","http:\/\/slideshare.net\/tag\/memcache","http:\/\/www.testking.org\/642-901.htm","http:\/\/www.testking.org\/642-812.htm","http:\/\/www.testking.org\/70-640.htm"];var wordpress_toolbar_url = "http://abhinavsingh.com/blog/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "oinw";var wordpress_toolbar_hash = "aHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZy8yMDA5LzAxL215c3FsLXF1ZXJ5LWNhY2hlLXdwLWNhY2hlLWFwYy1tZW1jYWNoZS13aGF0LXRvLWNob29zZS88d3B0Yj5NeVNRTCBRdWVyeSBDYWNoZSwgV1AtQ2FjaGUsIEFQQywgTWVtY2FjaGUgJiM4MjExOyBXaGF0IHRvIGNob29zZTx3cHRiPmh0dHA6Ly9hYmhpbmF2c2luZ2guY29tL2Jsb2c8d3B0Yj5BYmhpJiMwMzk7cyBXZWJsb2c%3D";</script><ul class="related_post"><li><a href="http://abhinavsingh.com/blog/2009/11/introducing-memchat-open-source-group-chat-framework-in-php-supporting-memcached-apc-sqlite-flat-files-and-mysql/" title="Introducing MemChat: Open source group chat framework in PHP supporting Memcached, APC, SQLite, Flat Files and MySQL">Introducing MemChat: Open source group chat framework in PHP supporting Memcached, APC, SQLite, Flat Files and MySQL</a> (32)</li><li><a href="http://abhinavsingh.com/blog/2010/02/memq-fast-queue-implementation-using-memcached-and-php-only/" title="MEMQ : Fast queue implementation using Memcached and PHP only">MEMQ : Fast queue implementation using Memcached and PHP only</a> (17)</li><li><a href="http://abhinavsingh.com/blog/2010/01/wordpress-style-duplicate-comment-detected-using-memcached-and-php/" title="Wordpress style &quot;Duplicate comment detected&quot; using Memcached and PHP">Wordpress style &quot;Duplicate comment detected&quot; using Memcached and PHP</a> (9)</li><li><a href="http://abhinavsingh.com/blog/2009/12/how-to-use-locks-for-assuring-atomic-operation-in-memcached/" title="How to use locks for assuring atomic operation in Memcached?">How to use locks for assuring atomic operation in Memcached?</a> (9)</li><li><a href="http://abhinavsingh.com/blog/2009/11/php-tokens-and-opcodes-3-useful-extensions-for-understanding-the-working-of-zend-engine/" title="PHP tokens and opcodes : 3 useful extensions for understanding the working of Zend Engine">PHP tokens and opcodes : 3 useful extensions for understanding the working of Zend Engine</a> (10)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://abhinavsingh.com/blog/2009/01/mysql-query-cache-wp-cache-apc-memcache-what-to-choose/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Caching problem in IE with Ajax : A Solution</title>
		<link>http://abhinavsingh.com/blog/2008/06/caching-problem-with-ie-with-ajax-a-solution/</link>
		<comments>http://abhinavsingh.com/blog/2008/06/caching-problem-with-ie-with-ajax-a-solution/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 13:21:39 +0000</pubDate>
		<dc:creator>Abhinav Singh</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://abhinavsingh.com/blog/2008/06/caching-problem-with-ie-with-ajax-a-solution/</guid>
		<description><![CDATA[Hello All, Problem Definition: I made my first browser based chat messenger way back in January this year, and I tried making a improved version of it yesterday again. But unfortunately Microsoft continues to give 1000 reasons for a web developer to suicide. They continue to serve the same old buggy browser way back in [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2008%2F06%2Fcaching-problem-with-ie-with-ajax-a-solution%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2008%2F06%2Fcaching-problem-with-ie-with-ajax-a-solution%2F&amp;source=imoracle&amp;style=normal&amp;service=bit.ly&amp;service_api=R_f027b5a79a20a49b713f16282f1e0857&amp;hashtags=Ajax,Caching,IE&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hello All,</p>
<p><span style="font-weight: bold; text-decoration: underline;">Problem Definition:</span><br />
I made my first browser based chat messenger way back in January this year, and I tried making a improved version of it yesterday again. But unfortunately Microsoft continues to give 1000 reasons for a web developer to suicide. They continue to serve the same old buggy browser way back in 2000 and even now.</p>
<p>The problem I was facing with IE7 (I haven&#8217;t tested on IE6), while trying to make a browser based chat messenger was that the chat application loads the chat messages from the server successfully only for the first time i.e. when you load the site for the first time. However, after that it continues showing the same old loaded data, even as new messages keep coming in the server. My chat application always worked fine in Firefox, Netscape, Safari and Flock. So what the hell with Internet Explorer.</p>
<p><span style="font-weight: bold; text-decoration: underline;">The Real Problem:</span><br />
I faced the same problem 6 months back and was facing it again now. Frustrating enough! As a web developer its a reason enough to die. Anyways, I finally tried analyzing the things. I went around installing <a href="http://www.wireshark.org/">Wireshark</a> , which lets you see each and every http request made from your computer. Unfortunately, It was just not showing any ajax request being made by my site (opened on IE). What the hell? However, it showed successful ajax requests being made by my site opened on Firefox.</p>
<p>Enough! The problem was clear that, for some reason IE was not allowing the Ajax request being made. Then I went around installing <a href="http://www.debugbar.com/?langage=en">IE Debug Bar</a>, there in the HTTP(S) section you can see each and every single request being made by IE. I restarted IE and opened my site again. There in the HTTP(S) section, I could see ajax request being made successfully every 15 seconds as intended (a live chat application will set that to about 2 seconds). Then why the hell was <span style="font-style: italic;">wireshark</span> not showing the same.On further investigation with <span style="font-style: italic;">DebugBar</span> I found this was what was not allowing my site to make a successful ajax request the second time:</p>
<ul>
<li><span style="font-weight: bold;">In the </span><span style="font-style: italic; font-weight: bold;"><span style="text-decoration: underline;">Headers</span> </span><span style="font-weight: bold;">section of HTTP(S) I could see:</span><br />
GET /ajax.php?getchatmessage=true&amp;id=36&amp;username=imoracle HTTP/1.1<br />
Accept: */*<br />
Accept-Language: en-in<br />
Referer: http://altertunes.com/home.php<br />
UA-CPU: x86<br />
Accept-Encoding: gzip, deflate<br />
HTTP/1.1 200 OK<br />
X-Powered-By: PHP/5.2.5<br />
Keep-Alive: timeout=5, max=100<br />
Transfer-Encoding: chunked<br />
Content-Type: text/html</p>
</li>
<li><span style="font-weight: bold;">In the </span><span style="font-style: italic; font-weight: bold;">Timing</span><span style="font-weight: bold;"> section of HTTP(S) I could see:</span><br />
Request start time: Thu, 05 Jun 2008 22:29:55<br />
All request retrieved from cache (no server request)</p>
</li>
<li><span style="font-weight: bold;">Further, in the </span><span style="font-style: italic; font-weight: bold;">Info &amp; Cache</span><span style="font-weight: bold;"> section of HTTP(S) I could see:</span><br />
URL: http://altertunes.com/ajax.php?getchatmessage=true&amp;id=36&amp;username=imoracle<br />
Content Type: text/html<br />
Headers size (bytes): 336<br />
Data size (bytes): 3<br />
Total size (bytes): 339<br />
Transferred data size (bytes): 0<br />
Cached data: Yes<br />
Cache File: C:\Users\abhi\AppData\Local\Microsoft\Windows\Temporary Internet Files\Low\Content.IE5\O184DNEL\ajax[1].htm<br />
Cache expires: Thu, 01 Jan 1970 05:30:00<br />
Cache last modified: Thu, 01 Jan 1970 05:30:00
</li>
</ul>
<p>Hence the conclusion was, IE do make an ajax request every 15 seconds as intended. But as it always reads the content from the the browser cache, it never gets the new messages from the server. And hence, <span style="font-style: italic;">Wireshark</span> was unable to show any request being made from IE browser, as the request never goes out of the computer.</p>
<p><span style="font-weight: bold; text-decoration: underline;">Solution to this disaster:<br />
</span>I tried looking for many solutions available over internet. A few of them asks to set some settings in your browser, which will force browser to read all the data from server directly. But for two reasons you surely won&#8217;t like to do this:</p>
<ol>
<li>You surely would like to cache your various images, css and other files for faster loading of your website.</li>
<li>Next, You simply can&#8217;t expect your users to do the settings, just to make sure that your ajax runs on IE.</li>
</ol>
<p>A few other sites asked to set a header information at the top of the php page. Probably something like this:</p>
<p><strong style="font-weight: normal;">  header(&#8220;Last-Modified: &#8221; . gmdate(&#8220;D, d M Y H:i:s&#8221;) . &#8221; GMT&#8221;);<br />
  header(&#8220;Cache-Control: no-store, no-cache, must-revalidate&#8221;);<br />
  header(&#8220;Cache-Control: post-check=0, pre-check=0&#8243;,false);<br />
  header(&#8220;Pragma: no-cache&#8221;);</p>
<p>But even after setting the following header IE was not allowing the ajax requests to fetch the data from the server.</p>
<p><span style="font-weight: bold; text-decoration: underline;">Working Solution:</span><br />
Then I thought of why not make my ajax requests look unique every time it is fired. i.e. if my ajax request seems like this in the firebug:</p>
<p>http://altertunes.com/ajax.php?getchatmessage=true&#038;id=36&#038;name=imoracle</p>
<p>why not make it look like this the next time:<br />
</strong><strong style="font-weight: normal;">http://altertunes.com/ajax.php?getchatmessage=true&amp;id=36&amp;name=imoracle&amp;timeid=1234.4323</p>
<p>and like this the very next time:<br />
</strong><strong style="font-weight: normal;">http://altertunes.com/ajax.php?getchatmessage=true&amp;id=36&amp;name=imoracle&amp;timeid=4324.3589</p>
<p>I tried this up and Bingo! My ajax was working just as great, as it was in any other browser.</p>
<p>I simply changed the url in my ajax request from:<br />
</strong><strong style="font-weight: normal;">http://altertunes.com/ajax.php?getchatmessage=true&amp;id=36&amp;name=imoracle to<br />
</strong><strong style="font-weight: normal;">http://altertunes.com/ajax.php?getchatmessage=true&amp;id=36&amp;name=imoracle&amp;timeid=(Math.random()*100000)</p>
<p>and yes, I have my chat messenger working great now.</p>
<p>Try out this solution if you are facing a similar problem with your Ajax requests. I will try to test the same in IE6 if I can find one, but I am pretty sure it will work great there too.</p>
<p>Feel free to post your comments and modified solutions if any.</p>
<p>Happy Ajaxing.</p>
<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/api.tweetmeme.com\/share?url=http%3A%2F%2Fabhinavsingh.com%2Fblog%2F2008%2F06%2Fcaching-problem-with-ie-with-ajax-a-solution%2F","http:\/\/www.wireshark.org\/","http:\/\/www.debugbar.com\/?langage=en"];var wordpress_toolbar_url = "http://abhinavsingh.com/blog/wp-content/plugins/wordpress-toolbar/toolbar.php";var wordpress_toolbar_oinw = "oinw";var wordpress_toolbar_hash = "aHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZy8yMDA4LzA2L2NhY2hpbmctcHJvYmxlbS13aXRoLWllLXdpdGgtYWpheC1hLXNvbHV0aW9uLzx3cHRiPkNhY2hpbmcgcHJvYmxlbSBpbiBJRSB3aXRoIEFqYXggOiBBIFNvbHV0aW9uPHdwdGI%2BaHR0cDovL2FiaGluYXZzaW5naC5jb20vYmxvZzx3cHRiPkFiaGkmIzAzOTtzIFdlYmxvZw%3D%3D";</script><ul class="related_post"><li><a href="http://abhinavsingh.com/blog/2009/11/making-cross-sub-domain-ajax-xhr-requests-using-mod_proxy-and-iframes/" title="Making cross-sub-domain ajax (XHR) requests using mod_proxy and iframes">Making cross-sub-domain ajax (XHR) requests using mod_proxy and iframes</a> (20)</li><li><a href="http://abhinavsingh.com/blog/2009/01/mysql-query-cache-wp-cache-apc-memcache-what-to-choose/" title="MySQL Query Cache, WP-Cache, APC, Memcache &#8211; What to choose">MySQL Query Cache, WP-Cache, APC, Memcache &#8211; What to choose</a> (44)</li><li><a href="http://abhinavsingh.com/blog/2008/05/gmail-type-attachment-how-to-make-one/" title="Gmail Type Attachment &#8211; How to make one?">Gmail Type Attachment &#8211; How to make one?</a> (21)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://abhinavsingh.com/blog/2008/06/caching-problem-with-ie-with-ajax-a-solution/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

