I sending query for some service and get back result. I want to know if I already get the same "answer" in the past. So, I planing to use Azure Table as a cache mechanism.
I making this small 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);
When I run this code in the first time, it's working fine. At the end of this, I have 2 rows in the table.
The problem is in the second run. When I execute this code:
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);
(Note to the add of customer3)
What I expecting to get is a message that say:
- customer1 - exists
- customer2 - exists
- customer3 - added
What I actually get is this exception (on the ExecuteBatch() method):
Request Information RequestID:5116ee8a-0002-0024-7ac1-415787000000 RequestDate:Fri, 18 Nov 2016 17:33:08 GMT StatusMessage:0:The specified entity already exists. ErrorCode:EntityAlreadyExists
The server found that the #1 entity is exist, therefore, skip the whole task.
How can I get the expected answer?
The naive solution, is to try the add all N items, one by one. But this solution is the most slow one (N HTTP requests instead 1 request).