Search code examples
azureazure-caching

azure cache preview


I tried the new azure preview that came with the new sdk on my computer. I put a worker role with cache preview and put co-located role with 30% cache size. on my controller i put this code:

 [OutputCache(Duration=int.MaxValue, VaryByParam="none")]
    public ActionResult Index()
    {
        ViewBag.Message = "Welcome to ASP.NET MVC!";
        ViewBag.Id = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CurrentRoleInstance.Id;
        return View();
    }

now i ran the worker role via the emulator with 4 instances. the result was that every time i saw a different id - which mean the output cache never work with all the 4 instances ( to be clear i configure the output cache to work with the cache preview).

Only when i put an extra cache worker role as dedicated role everything start to work like it should be.

My questions is: Do i need the extra worker role to actually make the cache preview to work ok? - which mean the trade off of not working with azure appfabric cache is putting extra machine

Did i do something work and it should work with the web roles as co located roles?

thanks

edit: this another section of my web.config

<dataCacheClients>
<tracing sinkType="DiagnosticSink" traceLevel="Error" />
<dataCacheClient name="default">
  <autoDiscover isEnabled="true" identifier="NugetTest" />
  <!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />
</dataCacheClient>

if my identifier have NugetTest ( which is my web roles - which i have 4) every time i switch machine i get a different cache. if i change the identifier to my worker role i get the result


Solution

  • Can you add applicationName tag in the provider configuration in web.config of you app? If this is not added, instances will not share the cache across. Please note the applicationName tag. This should be added for the web.config of webrole in both dedicated or colocated cache scenario. Please reply if this solves your issue.

    <caching>
      <outputCache defaultProvider="DistributedCache">
        <providers>
          <add name="DistributedCache" type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache" cacheName="<cacheName>" applicationName ="<anyName>" dataCacheClientName="<dataCacheClientName>" />
        </providers>
      </outputCache>
    </caching>