Search code examples
javascriptoffice-jsoffice-app

How to ignore/clear Excel Task Pane App cache?


I am writing a Task Pane app for Excel using the Office JavaScript API. In this app I request data from an other server and show this data in the Excel worksheet. changes in the worksheet can also be uploaded to the server. The requests are simple ajax calls to an proxy. The proxy will forward this request to the server. This works fine so far.

But the request are cached somewhere in the Excel App. After the change, It still shows the unchanged data in the worksheet after a refresh. But the data are changed on the server side. It does not send a new request to the proxy, therefore it is cached in the app. It works fine if I call the app with Chrome and Firefox. Nothing gets cached here.

Is there a possibility to avoid the caching in the Office App? Or can I trigger an invalidation/clear of the cache manually?

EDIT:

What do I mean with unchanged data: I change something in the excel table and upload this data to the server. If I now refresh the data in the excel sheet, it will show me the data before the changes, because it cached the data from the first request somewhere and uses them. It does not make another call to the server to get the data with the changed values. Hope this explanation helps.

Can add some code examples here, but I don't think they will be a big help.

Method to get the data via ajax call. This method gets still called and runs threw the callbacks, but the request does not reach the proxy server, when I refresh the data in the excel app.

_downloadPeriods: function _downloadPeriods(sParameters) {
        var oController = this;

        ...

        var url = '/Proxy/RequestHandler.ashx/MaintainPeriodsExcelSet' + sParameters;
        // ajax request to load the data from the sap backend server via the proxy
        $.ajax({
            type: 'GET',
            url: url,
            dataType: 'json',
            success: function success(oData) {
                // create a material collection from the data
                oController.resetMaterialCollection();
                var oMaterialCollection = oController.getMaterialCollection();
                oMaterialCollection.updateData(oData.d.results);
                // insert data into the excel worksheet
                try {
                    oController._updateExcelTable(oMaterialCollection);
                } catch (e) {
                    // error handling
                }
                fnCallback();
            },
            error: function error(oErr) {
                // error handling
            }
        });
    },

I already set the caching headers in the proxy, but it still get's cached somewhere in the excel app.

...
context.Response.Headers["cache-control"] = "private, max-age=0, no-cache";
...

Solution

  • Disabling the cache in ajax did the trick.

    $.ajax({
            type: 'GET',
            url: url,
            cache: false,
            dataType: 'json',
            success: function success(oData) {
               ...
            },
            error: function error(oErr) {
                // error handling
            }
        });