Setting up a Dojox.app cached store using config.json file

183 views Asked by At

I'm trying to create a Dojox.app that reads data from a server once and then queries that data as needed during the lifetime of the app. A "dojo/store/JsonRest" will fetch the data and the "dojo/store/Memory" will be used as the cacheing repository. The process of creating the cache is straight forward for a normal dojo web page.

require(["dojo/store/JsonRest", "dojo/store/Memory", "dojo/store/Cache", "dojo/store/Observable"], function(JsonRest, Memory, Cache, Observable){ masterStore = new JsonRest({ target: "/Inventory/" }); cacheStore = new Memory({}); inventoryStore = new Cache(masterStore, cacheStore);

However for a Dojox.app a config.json file is used to set up the various MVC components including data stores.

The store and model portion of the json file could be similar to

   "stores": {
    "restStore":{
        "type": "dojo/store/JsonRest",
        "observable": true,
        "params": {
            "target": "/s/server/nowShowing.pl",
            "idProperty": "filmNo"
        }
    },
    "memoryStore": {
        "type": "dojo/store/Memory",
        "observable": true,
        "params": {
            "idProperty": "filmNo"
        }
    },
    "filmStore": {
        "type": "dojo/store/Cache",
         "params": {
            "masterStore": {"$ref":"#stores.restStore"},
            "cachingStore": {"$ref":"#stores.memoryStore"},
            "idProperty": "filmNo",
        }            
    }
},
"models": {
    "store": {
        "modelLoader": "dojox/app/utils/mvcModel",
        "type": "dojox/mvc/StoreRefController",
        "params":{
            "store": {"$ref":"#stores.filmStore"},
            "query": {}
        }
    }
},

I know that the cache store is a wrapper and not a true store. I also know that there would be a way to configure a dojo store cache via the config.json file but I haven't been able to find out how to do it. Mr Google didn't have the answer and the dojo tests came up blank as well.

The MVC model gives application wide access to the data via the loadedStores and loadedModels parameter of each view class.

2

There are 2 answers

1
frank On

You can have a look at the tutorial here (dojox.app) and here dojox.app reference guide for creating the dojo store.

0
nsharrok On

There is no example, demonstration or dojo test, I have found, of reading data from a file into a Memory store via config.json. All of the tests on GitHub have the data as static json embedded in the app structure.

I need a way to get dynamic display data from the server to my app. After more research I hit upon a workaround. It turns out that I didn't need use "dojo/store/Cache" to cache the data.

Three easy steps.

  1. Modify the json file into a JS file by adding

var myJson = [{"filmNo":"2792",...

  1. Read the data into the app via a script link

<script type="text/javascript" src="/s/server/myJsonFile.js"></script>

  1. In the config.json file make a reference to the myJson variable

"stores": { "filmStore": { "type": "dojo/store/Memory", "params": { "data" : "myJson", "idProperty": "filmNo" } }

Now my app really does zip from view to view