Example of using Transient Fault Handling with the AppFabric Cache in VB.NET

Topics: Building and extending application blocks, Caching Application Block
Mar 25, 2012 at 8:51 PM
Edited Mar 25, 2012 at 10:49 PM


The team should ALWAYS be supplying VB examples along with C#. VB developers should up-vote this post to alert MS for this need. We have to be pretty good at converting C# to VB due to so many C# examples out there, but I think I speak for the entire VB developer community when I say that it would save us a TON of time if you would produce all of the examples in both languages.

After going through the docs and examples, I have an example of how to run the cache (synchronously) in VB:

'***** Use the ExecuteAction method to return a value from the cache with the key "<var1><var2>"
'** Note that var1 & var2 were passed into this FN
'** Note that "(Of String)" must reflect what type of value is coming out. The call to "defaultCache(var1 & var2)" will be returning a string value - these types must match
'** Note that the entire ExecuteAction method call is then passing that return value from the cache back to become the return value of the entire FN
GetValue = appRetryPolicy.ExecuteAction(Of String)(Function() (defaultCache(var1 & var2)))

I posted a full example function over on Postoli at: http://www.postoli.com/Windows-Azure-AppFabric-Cache-Transient-Fault-Handling

To take a parameter but not returning anything, such as placing an object into the cache, change the ExecuteAction to reflect a Sub. Note that there is no assignment of any value from this statement because the Sub will not return a value.

appRetryPolicy.ExecuteAction(Sub() defaultCache.Put(key, datatable, TimeSpan.FromMinutes(20)))

I may post back something that works asynchronously later ... whenever I can get to it.

Don't forget to up-vote this if you found it helpful to send a message to MS about support for VB developers!

Luke Latham
SellRex Corporation