|
Possible to cache Web Chart Images? |
Posted by ConfusedCharter on Feb-02-2017 03:22 |
|
I am currently using chart director for .net graphing. Due to the way webchartviewer and other image saving methods append a cache busting query string to the end of the charting images, I am unable to get any client browser to cache these images even when they remain static for days at a time.
Is there a way to be able to disable these no-cache features of chart director? On some of my pages there can be 10-15 of these charts, and while I can cache the image server side using output caching, I still have to hit the page, and pull the image out of server cache.
This is delaying the performance of my page significantly, especially when these images do not change for days at a time. |
Re: Possible to cache Web Chart Images? |
Posted by Peter Kwan on Feb-03-2017 02:17 |
|
Hi ConfusedCharter,
If your web page obtains the URL from the WebChartViewer, it means it is creating 10 to 15 charts on the server side. It is reasonable to expect that your code would like to delivery those charts to the browser (otherwise why create them in the first place). So the WebChartViewer will try its best to deliver the charts, including using a cacheDefeat query parameter to make sure the browser does get the charts.
In many of our clients, the charts do not change frequently. For example, the chart may be an end-of-day stock chart which changes once per day. For this type of usage, the most common method is to create the charts and store them as image files on the server. When the user access the web page, the web page will check if the charts are up to date, and will create them only for out-of-date charts. The browser simply receives the URL pointing to those chart images (eg. by using WebChartViewer.ImageUrl = ..url_of_the_chart...). In this way, the browser would then cache them like any regular images, and the server only creates the chart if necessary.
In very old versions of ChartDirector, the charts are delivered using the "getchart.aspx" script and there is no cacheDefeat query parameter. The "getchart.aspx" method still works today (as we have always maintain backwards compatibility). The code is like:
myChartViewer.ImageUrl = "getchart.aspx?" + c.makeSession(Session, "chart1");
However, note that even without cacheDefeat, the browser would still not using cache if it starts a new session. It is because the URL generated will be session specific. This is to avoid one user from seeing the charts generated for another user. If the browser idles for sometime, the ASP.NET session will expire. The next time the browser loads the web page, ASP.NET will open a new session, and the the URL will ensure the browser would not load the charts from a previous session (which may or may not belong to the same user).
Regards
Peter Kwan |
|