32

Using Ext, default Ext.Ajax add to GET-request _dc parameter. For example

GET /ConnViewProcessing/?_dc=1263286227619

How to remove this parameter?

PS: it's necessary to manually cache response to ETag and If-None-Match.

Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102
ko1ik
  • 512
  • 1
  • 7
  • 12
  • for Ext-JS 6 those 3 methods dont work... the only thing i found was to put in the boot.js disableCaching: true, i know it makes no sense, but if you look at the code in boot.js, that's how it works. anyway, it doesn't really help, because then some of the callbacks are not functioning correctly. – zerkotin Jun 20 '16 at 13:14

14 Answers14

29

Set disableCaching option to false:

Ext.Ajax.disableCaching = false;
Lukman
  • 18,462
  • 6
  • 56
  • 66
22

Using Ext JS 4.1, and after adding the following code to app.js, the _dc parameter disappears:

// Disable _dc parameter

Ext.Loader.setConfig({
    disableCaching: false
});

// My App

Ext.application({
scvalex
  • 14,931
  • 2
  • 34
  • 43
Pencroff
  • 1,009
  • 9
  • 13
  • This only affects the loading of resources, not Ext.Ajax. In case others come across this answer and want to be able to disable cache busting for scripts etc when using Architect, or just want to disable it only when debugging I have posted an answer that provides more info [here](http://stackoverflow.com/a/30992255/857209) – Glenn Lawrence Jun 23 '15 at 02:36
17

The proper way to accomplish that with Sencha Cmd 6.x is to set a (global) switch in app.json (because all of those hacks and overrides might interfere unnecessarily with the functionality):

"loader": {
    "cache": true
},

Then run sencha app refresh, in order to update the application's bootstrap.json.

Alternatively, one can configure Ext.Loader (at run-time):

Ext.Loader.setConfig({disableCaching: false});

When scrolling upwards and reading the actual question, concerning Ext.Ajax (per request):

Ext.Ajax.request({url: '/ConnViewProcessing', disableCaching: false});

The result: no more _dc parameters on scripted requests.

@see Sencha Cmd 6.x - The Microloader.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • I had to do it this way after upgrading from Sencha Architect v2.2 to v3.2. It seems tha tthe run-time loader setting no longer seems to work, presumably because Architect now uses SenchaCmd. – Glenn Lawrence Jul 14 '15 at 05:12
  • 1
    I just discovered that I can disable the use of SenchaCmd by Architect 3.2 by disabling **Build Tools** in **Project Settings** -> **Framework** which means I can again use `disableCaching=false` in the loader settings, and even change it at runtime as shown [here](http://stackoverflow.com/a/30992255/857209) – Glenn Lawrence Jul 16 '15 at 23:32
10

Note that the use of Ext.Loader has changed in ExtJS 5.

In ExtJS 5, caching can be disabled:

  • temporarily by adding "?cache" to the end of the URL
  • by setting a cookie called 'ext-cache' with the value of 1
  • or by editing the file .sencha/app/Boot.js and setting the '_config.disableCaching' property to be true (overwriting the dynamic lookup).
Robert Watkins
  • 2,196
  • 15
  • 17
8

I am using ExtJS 4.2, but this should work for Ext JS 4.1 and on. In the proxy there is a property called noCache you should set this to false.

Ext4.define('Server',{
    extend: 'Ext4.data.Model',
    fields: [
            {name: 'id'},
            {name: 'key'},
            {name: 'value'}
    ],
    proxy: {
            type: 'rest',
            url : 'yaddayaddayadda',
            noCache: false,
            reader : {
                    type: 'json'
            }

    }
});

The reason my code says Ext4. is because I am using the sandbox mode as I move old Ext JS 3x code into 4.2

Mario S
  • 11,715
  • 24
  • 39
  • 47
Vince Cordaro
  • 81
  • 1
  • 1
  • Confirm that noCache works for Ajax Proxy under v4.2.1 (double negation sucks) – Radu Maris Feb 07 '14 at 18:29
  • Can confirm that this approach still works with Ext JS 6.6.0. If you're looking to disable the "don't cache" param on a Ajax requests to particular service(s) this method allows for that – Grant Humphries Nov 07 '18 at 20:42
7

This should work with extjs 4.0.7:

Ext.Loader.config.disableCaching = false;
Wilduck
  • 13,822
  • 10
  • 58
  • 90
Night Warrier
  • 381
  • 4
  • 12
4

Setting the flag disableCaching to false (double negation - yay!) on the Ext.data.Connection should do the trick.

For more, look at the disableCaching-documentation.

(Please note that quite a few classes in Ext seem to have the option available, so you might have to muck around a bit.)

Morten Siebuhr
  • 6,068
  • 4
  • 31
  • 43
2

For those that want to set "disableCaching: false" in Sencha Architect 3+, here is how..:

  1. In the project inspector window, select the top node, "Application"

  2. Then in the "Config" window below that where you set the object properties, etc, select "Loader Config".. in my case I had to click the "+" to the right of this as I hadn't set any items yet. This will create a new "LoaderXX" object in the "Project Inspector" window above; Loader25 in my case.

  3. Now either select the new object in the "Project Inspector" window, or click on the right arrow beside the new "LoaderXX" (Loader25 in my case). This will take you to the properties for the object.

  4. Untick the "disableCaching" item.

Save the project and refresh the browser window, and enjoy persistent breakpoints, etc, etc in Chrome.

Ads
  • 2,084
  • 2
  • 24
  • 34
  • Works as you described ! – Dejo Apr 03 '14 at 06:06
  • Didn't work for me with Architect v3.2. I didn't try earlier 3.x versions. The code is changed to set `disableCaching: false` but I suspect that this run-time loader setting no longer works because Architect now uses SenchaCmd when saving the project. Modifying the **app.json** file as per syslogic's answer did work however. – Glenn Lawrence Jul 14 '15 at 05:15
  • Sorry @GlennLawrence, Early 2014 thankfully was the last time I set eyes on Sencha Architect and Sencha Touch. :-) I think it was more the dodgy code that I inherited that made life so bad, or maybe it was the client. Either way, I'm not sad to see the back end of that project. – Ads Jul 16 '15 at 06:07
  • No worries @Ads. I just discovered that I can disable the use of SenchaCmd by Architect 3.2 by disabling **Build Tools** in **Project Settings** -> **Framework** which means that your answer is still valid. I figured out a way you can can even change it at runtime as shown [here](http://stackoverflow.com/a/30992255/857209) – Glenn Lawrence Jul 16 '15 at 23:37
1

The only way I was able to disable _dc in ExtJS 4.2.x globally on my project:

Ext.define('Ext.data.Connection', {override:'Ext.data.Connection', disableCaching:false });
Ext.define('Ext.data.proxy.Server', {override:'Ext.data.proxy.Server', noCache:false });
Ext.define('Ext.data.JsonP', {override:'Ext.data.JsonP', disableCaching:false });

This is ugly, but any other ideas?

1

This is how I did this:

Ext.Ajax.request({
    url: url,
    disableCaching:false
});
leshicus
  • 109
  • 1
  • 8
0

I decided that I wanted the cache to be destroyed client side, but server side I was using my own caching mechanism (PHP's APC).

I left the _dc in the Ext ajax request, but then removed it from the REQUEST_URI, and then use the REQUEST_URI as the basis for the cache key

I found this useful: Regular expression to remove one parameter from query string

Community
  • 1
  • 1
user2066719
  • 251
  • 3
  • 4
0

If you develop under Sencha CMD you can do like this

http://localhost:1841/?disableCacheBuster

or just

http://localhost:1841/?cache
nahab
  • 1,308
  • 17
  • 38
0

For all who are looking for a way to disable it in a newer version:

proxy: {
    type: 'ajax',
    noCace: false
}
Dinkheller
  • 4,631
  • 5
  • 39
  • 67
-1

I use Ext.NET on top of Ext.JS. It adds some more voodoo to Ext.js... I tried to get rid of the dc= parameter, but all mentioned configurations did not work. So, this is my uber-effective, uber-dirty solution:

Ext.Date.now = function () { return ""; }

As far as I can see, Ext.Date.now() is only used for the caching logic. So it should be relativity save.

Johannes Hoppe
  • 251
  • 3
  • 10