View Full Version : disableCaching in Ext.chart.Chart only works if timestamps happen to be unique

6 Nov 2012, 6:46 AM
We had a problem with Ext.chart.Chart, where we had 6 charts on the page, and with disableCaching set, it was possible for the cache buster to fail if the timestamp for 2 charts were the same. This would result in a 304 (Not Modified) request for a chart, resulting in a blank white flash applet (no chart rendered). The code in Ext.chart.Chart.initComponent that manages this that contains the bug:

this.url = Ext.chart.Chart.CHART_URL;
this.url = Ext.urlAppend(this.url, String.format('{0}={1}', this.disableCacheParam, new Date().getTime()));

I created a plugin that fixes the problem:

//enforce charts to always have unique caching id by appending this value, instead of using
//extjs's algorithm which always just gets the current time in millis, which can fail if the code
//runs fast.

Ext.ux.plugins.ChartNoCachePlugin = (function() {

return {
init: function(chart){
chart.url += '_' + Ext.ux.plugins.ChartNoCachePlugin.index++;

Ext.ux.plugins.ChartNoCachePlugin.index = 0;

//and to use the plugin you would specify in your chart config:
plugins: [new Ext.ux.plugins.ChartNoCachePlugin()]

As this appears to be a global bug, it probably would be better to override Ext.chart.Chart.initComponent instead of use a plugin, but that is the route we chose to take to minimize our regression testing.