Azure Cache Preview - Retry logic, best practice
-
31 กรกฎาคม 2555 20:47
I'm trying to figure out what the best practice would be for retry logic on Azure Cache Preview... Before we switched to the "Preview" cache we used the Transient Fault Handling (Topaz) library, but it's not compatible with Cache Preview, so now I need to fab my own.
This is what I came up with, but with this logic we noticed a significant rise in CPU usage...
var data = CacheActionRetryBlock(() => (T)_cache.Get(key))
private T CacheActionRetryBlock<T>(Func<T> cacheFunction) { var maxRetries = 10; var delayMs = 100; for (var retry = 0; retry < maxRetries; retry++) { try { return cacheFunction.Invoke(); } catch (Exception ex) { if (retry < maxRetries) { Thread.Sleep(delayMs); } else { throw ex; } } } return default(T); }I've also stumbled across this piece of code Azure + Bing Maps: Accessing spatial data with Entity Framework, which is very similar to my own implication but is using "Action" rather than passing a function delegate.
The question is, how can I improve on the logic above? Keep in mind this will be used on a Azure Web Role.
Thanks in advance.
ตอบทั้งหมด
-
1 สิงหาคม 2555 5:08ผู้ดูแล
Hi,
Do you ever use EnterpriseLibrary to create Caching retry policy, i think you can have a try with below links.
Article:
Sample:
http://code.msdn.microsoft.com/windowsazure/CSAzureRetryCache-c26c894b#content
Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
-
1 สิงหาคม 2555 23:23That is exactly what we used when we were using Azure AppFabric Cache. I did try using it with Preview Cache but I kept running into assembly version conflicts, maybe I need to revisit this.
Anyone had a go implementing that with Azure Preview Cache? -
2 สิงหาคม 2555 1:56ผู้ดูแล
Hi,
Yes, they are Azure shared caching service sample and article, because Azure role-based caching service is very new feature, so we dont provide some may samples and articles, but i think the retry policy code logic is simple, you can try to implement it with Azure preview caching service.
If you need samples about this, try to post it as sample request to Microsoft All-In-One Code Framework, i believe they were glad to help you:
http://1code.codeplex.com/workitem/list/basic
Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
- ทำเครื่องหมายเป็นคำตอบโดย Arwind - MSFTModerator 6 สิงหาคม 2555 7:35