cache control?

cache control?

degenarodegenaro Posts: 24Questions: 1Answers: 0
edited March 2013 in DataTables 1.9
My javascript looks like this:

[code]
oTable.fnReloadAjax("/ducc-servlet/json-format-aaData-jobs",ducc_load_scroll_jobs_callback);
[/code]

Using FF, about:cache show lots of entries line this:

[code]
http://myhost.my.domain.com:42133/ducc-servlet/json-format-aaData-jobs?_=1362577190455
http://myhost.my.domain.com:42133/ducc-servlet/json-format-aaData-jobs?_=1362577552438
...
[/code]

where each entry has a different trailing number.

How can I prevent the browser cache from filling up with these non-reusable entries? I've tried several Cache-Control directive, but they seem to be ineffective (and not seen in the cache!).

Thanks.

Lou.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited March 2013
    Because DataTables sets the jQuery anti-cache parameter. At the moment you either need to alter the DataTables core code to remove that or define your own fnServerData . In v1.10 (not yet released but it is in git if you want to try the bleeding edge) you can do:

    [code]
    $('#example').dataTable( {
    "ajax": {
    "url": "...",
    "cache": true
    }
    } );
    [/code]

    Allan
  • degenarodegenaro Posts: 24Questions: 1Answers: 0
    I apologize for be quite naive here (javascript is not my strength!) but I took fnReloadAjax from someplace on this site, I'm fairly certain. Is it a matter of hacking that function? If so, could you post a no-cache version of fnReloadAjax on this site. Or I could post that original code here and you could demonstrate how to hack it?

    Your help is greatly appreciated.

    Lou.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Nothing to do with fnReloadAjax - that plug-in makes DataTables call its own Ajax get method (that's all fnReloadAjax is if you look at the code - it pokes DataTables - it doesn't make its own Ajax call). My original comment stands: use 1.10.dev (if you are brave), fnServerData or alter DataTables.

    Allan
  • degenarodegenaro Posts: 24Questions: 1Answers: 0
    I'm happy to hack 1.9 core code for the moment, but alas don't know where/how.

    Lou.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Open the file and search for `"cache": false` ... :-)
  • degenarodegenaro Posts: 24Questions: 1Answers: 0
    I see just one place in jquery.dataTables.js that says "cache": false at line 8544...just change it to true?
  • degenarodegenaro Posts: 24Questions: 1Answers: 0
    So what's really going to happen when set to true? I really want the data to be fetched from webserver every time. Otherwise the data will be stale, which is undesirable.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    So you don't want it cached? In which case, just leave it. I don't really understand I'm afraid. You said:

    > How can I prevent the browser cache from filling up with these non-reusable entries? I've tried several Cache-Control directive, but they seem to be ineffective (and not seen in the cache!).

    But you now say you want it specifically not to be cached?
  • degenarodegenaro Posts: 24Questions: 1Answers: 0
    Actually I'm using jquery.dataTables.min.js so I hacked "cache":!1 to !0.
  • degenarodegenaro Posts: 24Questions: 1Answers: 0
    edited March 2013
    The behavior that's wanted is a) to fetch from webserver every time and b) don't fill up cache with "unique" entries.

    Before we stated this discussion, I was seeing the data seemingly fetched every time, but leaving a "unique" cached copy in memory each time, chewing up valued virtual storage in the browser.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > The behavior that's wanted is a) to fetch from webserver every time and b) don't fill up cache with "unique" entries.

    I'm afraid I really don't understand. The two are mutually exclusive. Either it can be cached, or not.

    > Before we stated this discussion, I was seeing the data seemingly fetched every time, but leaving a "unique" cached copy in memory each time, chewing up valued virtual storage in the browser.

    It should only be cached in the develop tools you are using. DataTables does not retain a copy of the data if you are using fnReloadAjax.

    Allan
  • degenarodegenaro Posts: 24Questions: 1Answers: 0
    If you go up to my original post, you see that I complain that when I issue about:cache I see many, many entries like this:

    http://myhost.my.domain.com:42133/ducc-servlet/json-format-aaData-jobs?_=1362577552438

    where each has a different number at the end. Who's doing that? These are refresh requests to my webserver for the dataTable contents.

    Lou.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Okay, sorry - I've not fully understood. The number is the jQuery anti-cache parameter which is why I was talking about that. That will force a different data get every time. However, if you have set the cache control to no-cache, those individual requests should not be cached. I don't know why they would be if cache control is set I'm afraid.

    Allan
  • degenarodegenaro Posts: 24Questions: 1Answers: 0
    At the end of the day, it seems like the right answer is to use the "hack" to 1.9. With this, I get the desired behavior: the browser cache does not fill up with lots of "unique" entries, and the data is current (I suppose because the Cache-Control directive "no-cache" tells the browser to ignore what's in the cache...why the browser keep this trash and wastes precious memory is beyond me).

    Thanks for your help. Would have taken me forever otherwise.

    Lou.
This discussion has been closed.