mar*_*ley 6 java google-app-engine
我正在开发一个小项目来了解Google App Engine,该项目是Java并且有Customer对象,Customer的实例可以有策略.每个客户都在自己的实体组中,以便可以使用事务来修改客户.
该站点的主页是客户列表,当添加新客户时,将再次显示客户列表.
由于每个客户都在他们自己的实体组中,因此新添加的客户有时不会出现在新客户列表中,几秒钟后刷新客户列表并且客户将出现.删除客户时存在类似的问题,您删除了客户,但它在整个列表中显示几秒钟.据我所知,由于数据存储提供的最终一致性,因此可以在Google App Engine中实现这一点.
所以我试图通过使用memcache来存储最近添加或最近删除的客户来解决这个问题.我正在使用的代码如下.
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;
}
Run Code Online (Sandbox Code Playgroud)
我在这里问,因为我认为我正在采取的方式不会感觉到"正确"的方式,并希望听到那些知道更好的方法来解决最终一致性产生的问题的人.
| 归档时间: |
|
| 查看次数: |
1676 次 |
| 最近记录: |