Sorry Isomorphic,
it’s my fault, I’ve written gibberish, like a crashed server:-)
I will try to be more precise:
as you suggested I’ve used the method updateCaches() after a fetch by id (getting a single row).
I guess updateCaches () has 2 main effects:
- integrates fresh copy of existing data from server with the local - existing - copy (similar to an update operation… insomuch as we have to simulate an UPDATE operation setting the operationType on the request)
- forces every visual components bound to the target datasource to “refresh” their appearance, hence showing the fresh copy.
This works perfectly as long as I am fetching a single record that needs updating (as you previously said), but doesn’t seem to be the right strategy when I need to re-fetch the entire DataSource (in a high level of concurrency the chance that some records have been changed, added or removed is too high, so I want that changes reflected to the visual components as soon as possible).
In that case, I could use invalidateCache() on the DataSource and then fetch all data, but I never obtain the second - and only appliable for this scenario - effect that an updateCaches() call instead would give: triggering the refresh/redesign of every visual components bound to that datasource.
So the question is: how can I force every visual component bound to a certain datasource to resynch with its model when I cannot use using updateCaches()?
I don’t want to operate directly on the visual components (mainly listgrids): they are sharing the same DataSource also to centralize that kind of management.
Directly setting the data into the visual components (or their resultsets) isn’t so attractive, cause I guess it leads to disconnected data, hence to the need to directly manage every call to the server for data changes…
I’ve tried setting cacheAllData to true: that way the datasource seems to automatically switch to local-only (from Developer Console I see my fetches with URL “[local only]”, so frustrating any subsequent automatic refresh.
A simple call to invalidateCache() on the datasource clearly is not enough.
This is a snippet from my attempts to assemble an automatically refreshed DataSource
final int cacheTimeout = 30;//high frequency for test purposes
//setCacheAllData (true);
//setAutoCacheAllData (true);
//setCacheMaxAge (cacheTimeout);
/*
* local data automatic refresh
*/
final Timer t = new Timer () {
private int errorCount = 0;
public void run () {
try {
SC.logWarn ("Automatically fetching data for cache timeout");
invalidateCache();
fetchData (null, new DSCallback() {
@Override
public void execute (DSResponse response, Object rawData, DSRequest request) {
SC.logWarn ("Data automatically fetched for cache timeout");
/*
* HERE I would need to call updateCaches or something else to pass
* the fresh data to visual components resultsets
*/
}
});
} catch (final Exception e) {
errorCount++;
if (errorCount>3) {
SC.logWarn ("Disabling automatic refresh for datasource "+getID ()+", since it just failed for 3 times");
cancel ();
}
}
}
};
t.scheduleRepeating (cacheTimeout*1000);
Hope I made myself somewhat clear this time…
Kind regards
Davide