I'm creating a new MVC app to pull data from an Azure Data Cache. However, as soon as I try and instantiate a DataCache
object, my code just hangs indefinitely. I don't get an error or timeout, it just sits there trying to create the new object.
At the moment my code is literally no more than:
public ActionResult Index()
{
DataCache cache = new DataCache();
Debugger.break;
}
buts never gets past the new DataCache()
statement. If I pause the debugger in visual studio I can see it pausing on the new DataCache()
line so that's definitely where execution has stalled.
My web.config has the section added by NuGet when I imported the new azure caching package as follows:
<dataCacheClients>
<dataCacheClient name="default">
<!--To use the in-role flavor of Windows Azure Caching, set identifier to be the cache cluster role name -->
<!--To use the Windows Azure Caching Service, set identifier to be the endpoint of the cache cluster -->
<autoDiscover isEnabled="true" identifier="{{REMOVED}}" />
<!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />-->
<!--Use this section to specify security settings for connecting to your cache. This section is not required if your cache is hosted on a role that is a part of your cloud service. -->
<securityProperties mode="Message" sslEnabled="false">
<messageSecurity authorizationInfo="{{REMOVED}}" />
</securityProperties>
</dataCacheClient>
</dataCacheClients>
I've double checked the values in the web.config match with those in the Azure portal and they're oK.
Does anyone know the cause of this? I'm guessing its something quite basic given how new it is.
You are using Shared caching (Cache Service Preview) - the other two options are "In Role" caching - read more at Windows Azure Cache. Assuming that all your settings are correct in the config, then, you are not properly instantiating the cache. Read How to Use Windows Azure Cache Service (Preview). You need to use either:
or:
Finally, creating the cache object is expensive - you should create a new singleton class for the cache so that is gets created once - not every time an action is called. Here is a full example of the singleton class: