我发送某个服务的查询并取回结果。我想知道我过去是否已经得到相同的“答案”。所以,我打算使用Azure Table作为缓存机制。Azure存储表 - 插入批次行并检查它们是否存在
我做这个小POC:
TableBatchOperation batchOperation = new TableBatchOperation();
CachedUrl customer1 = new CachedUrl(Guid.Empty, "test1");
CachedUrl customer2 = new CachedUrl(Guid.Empty, "test2");
batchOperation.Insert(customer1);
batchOperation.Insert(customer2);
table.ExecuteBatch(batchOperation);
当我运行在第一时间将此代码,它的正常工作。在这最后,我在桌上有两排。
问题出在第二次运行。当我执行此代码:
TableBatchOperation batchOperation = new TableBatchOperation();
CachedUrl customer1 = new CachedUrl(Guid.Empty, "test1");
CachedUrl customer2 = new CachedUrl(Guid.Empty, "test2");
CachedUrl customer3 = new CachedUrl(Guid.Empty, "test3");
batchOperation.Insert(customer1);
batchOperation.Insert(customer2);
batchOperation.Insert(customer3);
table.ExecuteBatch(batchOperation);
(注到customer3
附加)
我期望得到是说一个消息:
- customer1表 - 存在
- customer2 - exists
- customer3 - 添加
我其实得到的是这个异常(在ExecuteBatch()
法):
索取资料请求ID:5116ee8a-0002-0024-7ac1-415787000000 RequestDate:星期五,2016年11月18日17:33:08 GMT状态消息:0:指定实体 已存在。 ErrorCode:EntityAlreadyExists
服务器发现#1实体存在,因此,跳过整个任务。
我该如何得到预期的答案?
天真的解决方案,是尝试添加所有N个项目,一个接一个。但是这个解决方案是最慢的一个(N个HTTP请求,而不是1个请求)。
?通过这种方式,在执行命令后,我无法知道这些项目是新添加的还是刚刚被替换的... – No1Lives4Ever
我不相信有方法可以判断实体是被替换还是只是被激活。也许表格存储不适合你正在尝试做的事情。你考虑过其他选择吗? –