2

I have a single Web Role, using MVC5.

In web role properties I selected Enable Caching.

In a controller in my MVC app I have:

 var cache = new DataCache("default");

But it throws an error:

"Server collection cannot be empty"

Is the controller the wrong place to create the cache object? I was just trying to put it where I might have used a session cache before.

user888734
  • 3,797
  • 5
  • 36
  • 67

2 Answers2

1

Sounds like you haven't actually configured your application to point to the cache server that was set up for you.

Here are instructions to do it via .config file.

Here are instructions to do it programmatically.

Drew Marsh
  • 33,111
  • 3
  • 82
  • 100
  • Thanks Drew. Is there such a thing as a development cache, in the same way as I can use development settings for tables and blob storage? I'm just finding my feet with Azure and can't afford a full account, so trying to do as much as possible in a local environment. – user888734 Jan 14 '14 at 22:08
  • No there isn't AFAIK. You would need to create a separate cache instance in Azure to dev against... either that or create a diff. cache name to against in the same instance, but beware that you would be competing with resources for your production cache entries then. – Drew Marsh Jan 14 '14 at 23:08
1

There is no need for you to make any code changes, you have two options.

1) Use In Role Caching mechanism and configure the application - http://msdn.microsoft.com/en-us/library/windowsazure/gg185668.aspx

2) Use Azure Cache Service - http://blogs.msdn.com/b/webdev/archive/2013/11/30/instant-azure-caching-with-mvc.aspx. There is also sample code in MSDN - http://code.msdn.microsoft.com/Windows-Azure-Caching-78a49b70

In either the cases you need to configure the application's web.config and still go ahead and use Session state.

ramiramilu
  • 17,044
  • 6
  • 49
  • 66