how to disable Cache in a REST Tree in DOJO with a complete code to reproduce it

236 Views Asked by At

The following code shows a tree in Dojo using dojox.data.JsonRestStore with one node named Changing0 with children to be lazy loaded. the problem is in updating the tree by renaming the one node (Changing1, Changing2,...) without changing its reference number or id. The question is the following: if it is a caching problem, how to disable caching. Please note that on the log file we can see that the REST is functioning well but the name is unchanged on the tree. Even if we use refresh2() instead of refresh1() by deleting the whole tree and its data and recreating it. Maybe it is the $ref that is kept in javascript referencing since we do not change the id. the code is the following: reproducing_problem.php:

<?php
if(!isset($_SESSION)) 
    { 
        session_start(); 
    } 
$_SESSION['keyA']=0;    
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Reproducing Cache Problem</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"-->
<script type="text/javascript" src="../external/dojo/dojo.js"  djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require('dojox.data.JsonRestStore');
dojo.require('dijit.Tree');
dojo.require("dijit.form.Button");

var prod= {
    store: null,
    model: null,
    tree: null,

    init: function() {
        this.store = new dojox.data.JsonRestStore({
            target: 'reproducing-REST.php',
            labelAttribute: "name"
        });

        this.model = new dijit.tree.ForestStoreModel({
            store: this.store,
            deferItemLoadingUntilExpand: true,
            rootId: "products",
            rootLabel: "Products",
            query: {queryOptions:{cache:false}},            
            childrenAttrs: ['children']
        });
    }
};
function refresh1() {
    tree=prod.tree
    tree._itemNodesMap = {};
    tree.rootNode.state = "UNCHECKED";
    tree.model.root.children = null;
    if (tree.rootNode) {
        tree.rootNode.destroyRecursive();
    }
    tree._load();
}
function refresh2() {
    delete prod.tree;
    delete prod.model;
    delete prod.store;
    dijit.byId('products_tree').destroy(true);
    prod.init();
    prod.tree = new dijit.Tree({
            model: prod.model,
            query: {queryOptions:{preventCache:true}},                      
            persist: false
        }, 'products_tree');
    prod.tree.startup();
}
dojo.addOnLoad(function() { 
    prod.init();
    //prod.store.fetch({queryOptions:{cache:false}});
    prod.tree = new dijit.Tree({
            model: prod.model,
            //query: {queryOptions:{cache:false}},  
            persist: false
        }, 'products_tree');
    prod.tree.startup();    
});

</script>
<style type="text/css">
@import "../external/dijit/themes/soria/soria.css";
@import "../external/dojo/resources/dojo.css";
</style>
</head>

<body class="soria">
    <div dojoType="dijit.form.Button">
       Change name and refresh
       <script type="dojo/event" event="onClick">
           refresh1();
       </script>
    </div> 
    <div id="products_tree"></div>
    <div id="notes">notes</div>
</body>
</html>

reproducing-REST.php:

<?php
if(!isset($_SESSION)) 
{ 
    session_start(); 
} 
$keyA=$_SESSION['keyA'];
$_SESSION['keyA']=$keyA+1;
if (array_key_exists('PATH_INFO', $_SERVER)) {
    $arr = null;
    $resource = $_SERVER['PATH_INFO'];
    $method = $_SERVER['REQUEST_METHOD'];   
    error_log("  resource: ".$resource." \n",3,"mylogfile.txt");    
    if ($method == 'GET') {
        if ($resource=='/'){
            $arr=array();   
            $sameref='1234';
            $name="Changing".$keyA;
            error_log("  name: ".$name." \n",3,"mylogfile.txt");
            array_push($arr,array('$ref' => $sameref, 'name' => $name, 'children' => true));
        }
        else{
            $aProduct = ltrim($resource, '/');
            $arr=array();
            $name="exploding";
            $child='2345';
            array_push($arr,array('name' => $name,'idq' => $child));
            $arr=array('idp' => $aProduct, 'name' => $name, 'children' => $arr);
        }
        $status = 'HTTP/1.1 200 OK';
    }
    header($status);
    echo json_encode($arr); 
}
?>

thank you

0

There are 0 best solutions below