I am new to App Engine and wrote a sample App. If i create or update a entity:
Entity record = new Entity(...);
... set properties
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(record);
and then redirect to a page where the new or updated entity is displayed
resp.sendRedirect("MainPage.jsp");
where the following code is executed
DatastoreService datastore =
DatastoreServiceFactory.getDatastoreService();
Query query = new Query(...).addSort(..., Query.SortDirection.DESCENDING);
List<Entity> entities = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(20));
The new record is not in the list. The page is updated (as shown by a timestamp displayed), but the new record or a modification of a existing record is shown only after a delay of up to some seconds when i refresh the page.
How can this be avoided? Is the DataStore possible not suited for such a thing?
I am using the Eclipse local test environment from GAE with Windows XP 64.
Yeah, this is called "eventual consistency" and is the default update model for HRD (now default on all new instances).
So putting an entity and then querying for it might not get is back (evental consistency), but putting it and then getting it (
get
via a key) will get it back immediately (strong consistency).Solution is either to:
get
instead of queries.Also, local dev server is only for testing and does not behave exactly as production instances, so you should always (eventually) test on production.
Since you are running on GAE, your best option is to use its Memcache for short-term retrieval (you still need to put stuff in the DataStore for persistence).