簡體   English   中英

如何忽略/清除Excel Task Pane應用程序緩存?

[英]How to ignore/clear Excel Task Pane App cache?

我正在使用Office JavaScript API編寫Excel的“任務窗格”應用程序。 在這個應用程序中,我從其他服務器請求數據,並在Excel工作表中顯示此數據。 工作表中的更改也可以上傳到服務器。 這些請求是對代理的簡單ajax調用。 代理會將請求轉發給服務器。 到目前為止,這個工作正常。

但是請求被緩存在Excel App中的某個位置。 更改后,刷新后它仍在工作表中顯示未更改的數據。 但是數據在服務器端已更改。 它不會向代理發送新請求,因此將其緩存在應用程序中。 如果我使用Chrome和Firefox調用應用程序,則效果很好。 什么都沒有緩存在這里。

是否有可能避免Office App中的緩存? 還是可以手動觸發對緩存的失效/清除?

編輯:

不變的數據是什么意思:我更改了excel表中的內容,並將此數據上傳到服務器。 如果現在刷新excel工作表中的數據,它將在更改之前向我顯示數據,因為它將第一個請求中的數據緩存在某個地方並使用它們。 它不會再次調用服務器來獲取具有更改后的值的數據。 希望這種解釋有所幫助。

可以在此處添加一些代碼示例,但我認為它們不會有很大幫助。

通過ajax調用獲取數據的方法。 當我刷新excel應用程序中的數據時,該方法仍被調用並運行,並引發了回調,但請求未到達代理服務器。

_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
            }
        });
    },

我已經在代理中設置了緩存頭,但是它仍然被緩存在excel應用程序中的某個位置。

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

禁用ajax中的緩存可以達到目的。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM