I am working on a small project to learn about the Google App Engine, the project is in Java and has Customer objects, Client instances can have a policy. Each client has its own group of individuals, so transactions can be used to change the client.
The main page of the site is the list of Clients, when a new client is added, the list of clients is displayed again.
Since each client is in its own group of entities, there are times when a newly added client does not appear in the new client list, updating the client list after a few seconds, and the client will appear. A similar problem exists when deleting clients, you delete the client, but it appears in the general list for a few seconds. I understand that this can be expected in the Google App Engine due to the possible sequence provided by the data store.
So, I tried to work around this problem using memcache to keep recently added or recently added clients deleted. The code I'm using is below.
public List<Customer> getCustomers() { List<Customer> cachedCustomers = myCache.getCached(); List<Customer> recentlyDeleted = myCache.getDeleted(); // Calls the real datastore. List<Customer> dbCustomers = customerDao.getCustomerList(); Set<Customer> allCustomers = new HashSet<Customer>(); // Add cached first as these are most the most up todate. allCustomers.addAll(cachedCustomers); allCustomers.addAll(dbCustomers); allCustomers.removeAll(recentlyDeleted); List<Customer> allList = new ArrayList<Customer>(); allList.addAll(allCustomers); Collections.sort(allList); return allList; }
I ask here because I think that the way I do it does not feel the βrightβ way to do it and wants to hear from those who know the best ways to get around the problems that the constant sequence creates.
source share