cache on browser

cache on browser

lawrancelawrance Posts: 3Questions: 0Answers: 0
edited February 2013 in DataTables 1.9
I use "sAjaxSource": "data/run_plan.txt" in my code , this file is about 34Mb, I do refresh every 10sec, the problem is that the browser load this file and store it in cache, so after a short time my disk it full, how can I disable the browser caching for this.

Replies

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin
    You'd need to configure your web-server to send no cache HTTP headers along with your file. How you do that will depend upon your web-server.

    However, are you sure it is the file that is taking up so much space? 34MB every 10 seconds is a massive amount of data. If there is a leak anywhere, that you are going to very quickly notice that. I'm not aware of any leaks in DataTables at this time, but it is always possible you are seeing the effects of one I don't know about... Try using the Chrome memory tools to see what is going on.

    Allan
  • lawrancelawrance Posts: 3Questions: 0Answers: 0
    I see in chrome cache directory the json file that I load, I already add to my header this


    but it didn't worked, does the datatables override the headers.

    it there a flag in datatables that tells "no cache" when loading json file ?
  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin
    > it there a flag in datatables that tells "no cache" when loading json file ?

    Actually yes - there is... The Ajax request DataTAbles makes by default set's jQuery's `cache` parameter. You'll need to define a custom Ajax request using fnServerData that doesn't enable the cache bypass.

    I will make this easier in 1.10...!

    Allan
  • lawrancelawrance Posts: 3Questions: 0Answers: 0
    edited February 2013
    thanks a lot it works.
  • lawrancelawrance Posts: 3Questions: 0Answers: 0
    Hi Allan,
    I notice lately that after added fnServerData to override the cache true to false I have 412 (Precondition Failed) ,so I couldn't load the data again
    here part of the code
    [code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">



    <!////////////////////////////////////////////include section/////////////////////////////////////////////////!>


    Monitor

    @import "DataTables-1.9.1/media/css/demo_page.css";
    @import "DataTables-1.9.1/media/css/demo_table.css";
    @import "css/innerhtml.css" ;

    <!--[if gte IE 9 ]><![endif]-->
    <!--[if !IE]>--><!--<![endif]-->





    ///////////////////////////////////////////////////////////Ready///////////////////////////////////////////////////
    $(document).ready(function() {
    var anOpen = [];
    var cbs = [];
    var hold = 0 ;
    var sImageUrl = "DataTables-1.9.1/examples/examples_support/";
    //refresh every 30sec
    var oTable = $('#run_plan').dataTable( {
    "bProcessing": true,
    "bServerSide" : false,
    //this save the cookies of the session
    "bStateSave": true ,
    "sAjaxSource": "data/run_plan.txt",
    //added to override the json loader to set cache false
    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
    oSettings.jqXHR = $.ajax( {
    "dataType": 'json',
    "cache": 'false',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": fnCallback
    } );
    },


    [/code]
  • lawrancelawrance Posts: 3Questions: 0Answers: 0
    Hi Allan,
    after adding the fnServerData to set the no cache I couln't load the data I get HTTP 1.1 error 412 (Precondition Failed), can you help please
    here part of the code

    [code]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">



    <!////////////////////////////////////////////include section/////////////////////////////////////////////////!>


    Monitor

    @import "DataTables-1.9.1/media/css/demo_page.css";
    @import "DataTables-1.9.1/media/css/demo_table.css";
    @import "css/innerhtml.css" ;

    <!--[if gte IE 9 ]><![endif]-->
    <!--[if !IE]>--><!--<![endif]-->





    ///////////////////////////////////////////////////////////Ready///////////////////////////////////////////////////
    $(document).ready(function() {
    var anOpen = [];
    var cbs = [];
    var hold = 0 ;
    var sImageUrl = "DataTables-1.9.1/examples/examples_support/";
    //refresh every 30sec
    var oTable = $('#run_plan').dataTable( {
    "bProcessing": true,
    "bServerSide" : false,
    //this save the cookies of the session
    "bStateSave": true ,
    "sAjaxSource": "data/run_plan.txt",
    //added to override the json loader to set cache false
    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
    oSettings.jqXHR = $.ajax( {
    "dataType": 'json',
    "cache": 'false',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": fnCallback
    } );
    },

    [/code]
This discussion has been closed.