Role-based caching in Windows Azure with the Compute Emulator
Role-based caching in Windows Azure with the Compute Emulator
When a new instance my Web role is launched using the VS (F5) debugger, it appears as though my (co-located) cache is cleared as the Web role is spun up. I'm adding items into the DataCacheFactory default cache. I am guessing this is the normal behavior. I am reading that items remain in the cache for 48 hours by default, otherwise, unless explicitly set so I was trying to emulate this behavior between sessions. In the cloud I would assume as long as there were two vms for the Web role instance then it would safely fail over, but wanted to confirm that also.
>> When a new instance my Web role is launched using the VS (F5) debugger, it appears as though my (co-located) cache is cleared as the Web role is spun up.
From my experience, in Compute Emulator, after a role is destroyed, all instances (simulated as processes) are destroyed, thus memory is reclaimed, and any in-memory cache is lost. This will also happen in the cloud if you completely redeploy your solution (so all instances are destroyed). If you do an in place upgrade, and if you have multiple instances, some of the co-located cache may preserve, but some may lose, because in co-located cache, there is no telling if cache is duplicate on all instances and in most cases it won't. I'd like to point out that actually reading from another instance is almost as fast as reading from local memory since the network within a data center is very fast, thus we do not have to duplicate cache. Also, this will reduce the memory available for caching, if you use dedicated cache, as long as the cache role is not updated, data would not lose. But occasionally data lose may still happen, as the cache instance may encounter error and has to be moved to another node, or the hosting OS needs to be updated and restarted.
So to sum up, cache is not meant to store permanent data. It is recommended to store permanent data in an external storage, such as Windows Azure storage or SQL Database.