I really, really need to see a concrete example of how to set up a cached DataSource. For performance reasons I need to be able download a fairly static set of data that is used all over my app.
The back-end is PHP serving up properly formed JSON. Here is the data source that I created that should be able to cache the results it gets.
The problem that I'm seeing is that since I have enabled the setCacheAllData to true the DS is making LOCAL calls rather than remote calls to the server and so no data is ever getting into the DS!
If someone could PLEASE point me in the right direction I would much appreciate it.
Thanks.
The back-end is PHP serving up properly formed JSON. Here is the data source that I created that should be able to cache the results it gets.
The problem that I'm seeing is that since I have enabled the setCacheAllData to true the DS is making LOCAL calls rather than remote calls to the server and so no data is ever getting into the DS!
If someone could PLEASE point me in the right direction I would much appreciate it.
Thanks.
Code:
public class ListCachedDataSource extends RestDataSource { private static ListCachedDataSource instance = null; public static ListCachedDataSource getInstance(){ if(instance == null){ instance = new ListCachedDataSource("DBList_CachedDS"); } return instance; } public ListCachedDataSource(String id){ setID(id); setShowPrompt(false); setDataFormat(DSDataFormat.JSON); setDataProtocol(DSProtocol.POSTPARAMS); setClientOnly(false); setDataURL(Utils.constants.url()); HashMap<String, String> m = new HashMap<String, String>(); m.put("app", "lists"); //m.put("cmd", "fetch"); setDefaultParams(m); setCacheAllData(true); setCacheMaxAge(120); setAddDataURL(Utils.constants.url()); DataSourceIntegerField idField = new DataSourceIntegerField("id"); idField.setHidden(true); idField.setPrimaryKey(true); DataSourceIntegerField attribField = new DataSourceIntegerField("attributeID"); attribField.setCanFilter(true); attribField.setHidden(true); DataSourceTextField descriptionField = new DataSourceTextField("description","Description"); DataSourceIntegerField parentField = new DataSourceIntegerField("parent"); parentField.setHidden(true); DataSourceIntegerField editField = new DataSourceIntegerField("editable"); editField.setHidden(true); setFields(idField,attribField,descriptionField,parentField,editField); } }