Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: If-None-Match & Etag

  1. #1
    Sencha User
    Join Date
    Jan 2010
    Posts
    9

    Default If-None-Match & Etag

    Hello!
    I want to cache Json data from simple ajax request.
    Code:
    disableCaching: false -- uses last midifided.
    How use If-None-Match and Etag?

  2. #2
    Sencha User
    Join Date
    Jan 2010
    Posts
    9

    Default

    Seems, that ETag and If-None-Match not supported in the ajax.

  3. #3
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    Did you also specify method:'GET' (you can't cache POST requests)?

  4. #4
    Sencha User
    Join Date
    Jan 2010
    Posts
    9

    Default

    Code:
        var defaultHeaders = {
            'If-None-Match':''
        };
        
        var store = new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: "/ConnViewProcessing/",
                disableCaching: false, // ? for last modifided
                defaultHeaders: defaultHeaders,
                   method:'GET',
                   success: function(response, opts) {    
                      Ext.apply(defaultHeaders,{'If-None-Match':response.getResponseHeader('ETag')});
                   },
                failure: function(response, opts) {
                    //
                }
            }),
            reader: new Ext.data.JsonReader({
                root: 'rows',
                id: 'pk',
                fields: ['pk','name', 'reference']
            }, [
                {name: 'id', mapping: 'pk'},
                {name: 'name', mapping: 'fields.name'},
                {name: 'reference', mapping: 'fields.reference'}
        ])
            //autoLoad: true 
        });
    How to cache in browser this json-data?

  5. #5
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    The whole ETag stuff is managed by the browser, so you don't have to do anything for that.

    You only have to make sure you are using:
    Code:
    disableCaching: false,
    method: 'GET'
    ps. You can only specify 'defaultHeaders' in the Connection constructor. In the actual request you have to specify 'headers'.

  6. #6
    Sencha User
    Join Date
    Jan 2010
    Posts
    9

    Default

    On
    Code:
    disableCaching: false,
    method: 'GET'
    server add to response next headers:

    Code:
    'Cache-Control'
    'Last-Modified'
    'Expires'(default Expires=10 min.)
    I want to use Etag: if document is changed, I get to response 200 Ok and json-data from server, else 304 NotDefined and get json-data out of cache

  7. #7
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    In that case your server needs to return an ETag. You don't have to do anything on the client, because the browser takes care of that.

  8. #8
    Sencha User
    Join Date
    Jan 2010
    Posts
    9

    Default

    I think so too, but not working..

    Code:
        
        var store = new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: "/ConnViewProcessing/",
                disableCaching: false, 
                method:'GET',
                success: function(response, opts) {    
                   //
                   },
                failure: function(response, opts) {
                    // 
                }
            }),
            reader: new Ext.data.JsonReader({
                root: 'rows',
                id: 'pk',
                fields: ['pk','name', 'reference']
            }, [
                {name: 'id', mapping: 'pk'},
                {name: 'name', mapping: 'fields.name'},
                {name: 'reference', mapping: 'fields.reference'}
        ])
            //autoLoad: true 
        });
    Code:
    Headers of response:
    
    Date: Mon, 11 Jan 2010 13:19:35 GMT
    Server: WSGIServer/0.1 Python/2.6.4
    Last-Modified: Mon, 11 Jan 2010 13:19:35 GMT
    Etag: "e1fb29ff-de3a-4f77-bba7-5f1272714b2d"
    Content-Type: text/javascript; charset=utf-8
    Expires: Mon, 11 Jan 2010 13:29:35 GMT
    Cache-Control: max-age=600
    
    Headers of request:
    
    Host: localhost:8000
    User-Agent: Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9.1.7) Gecko/20100106 Ubuntu/9.10 (karmic) Firefox/3.5.7
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: ru,en-us;q=0.7,en;q=0.3
    Accept-Encoding: gzip,deflate
    Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    X-Requested-With: XMLHttpRequest
    Referer: http://localhost:8000/g
    Cookie: sessionid=9a26026505d3ee096f2135c78e1844fb
    Next request don't includes header:
    Code:
    'If-None-Match':"e1fb29ff-de3a-4f77-bba7-5f1272714b2d"

  9. #9
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    Yes, you're correct. You indeed need to add the If-None-Match to XmlHttpRequests.

    How does your code work after you changed defaultHeaders to headers?

  10. #10
    Sencha User
    Join Date
    Jan 2010
    Posts
    9

    Default

    If using disableCaching: false, then obtaining on server "GET /ConnViewProcessing/ HTTP/1.1",
    else don't using, obtaining: "GET /ConnViewProcessing/?_dc=1263218247365 HTTP/1.1"
    in cache Firefox also.

    How delete "?_dc=1263218247365" in the request?

    Next code is correct?
    Code:
        var defaultHeaders = {
            'If-None-Match':''
        };
    
        var store = new Ext.data.Store({
            proxy: new Ext.data.HttpProxy({
                url: "/ConnViewProcessing/",
                disableCaching: false, 
                // disableCachingParam: '_dc',
                defaultHeaders: defaultHeaders,
                   method:'GET',
                   success: function(response, opts) {    
                    Ext.apply(defaultHeaders,{'If-None-Match':response.getResponseHeader('ETag')});
                   },
                failure: function(response, opts) {
                    // 
                }
            }),
            reader: new Ext.data.JsonReader({
                root: 'rows',
                id: 'pk',
                fields: ['pk','name', 'reference']
            }, [
                {name: 'id', mapping: 'pk'},
                {name: 'name', mapping: 'fields.name'},
                {name: 'reference', mapping: 'fields.reference'}
        ])
            //autoLoad: true 
        });
    With value disableCaching: false Etag and If-None-Match don't working.
    With value disableCaching: true Etag and If-None-Match working, but adding "?_dc=1263218247365" in the request.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •