How do I sync the in-memory cache among multiple web role instances?
My current approach is adding internal endpoints and notify the rest of instances through that port
foreach (RoleInstance roleInst in RoleEnvironment.CurrentRoleInstance.Role.Instances)
{
foreach (RoleInstanceEndpoint roleInstEndpoint in roleInst.InstanceEndpoints.Values)
{
// send payload to roleInstEndpoint.IPEndpoint
}
}
Is this the correct approach and is there any better solution?
Best,
Ryan
I'd recommend not using in-memory cache and moving to the Redis Cache offering in Azure. Then you don't have to try and sync cache between instances. If you don't want to pay for the Redis offering, you can move to Azure's In-Role cache, which uses available memory in each role instance for cache.