U4-1992 - cache is not refreshed properly for dictionary in load balanced environments

Created by Shannon Deminick 22 Mar 2013, 15:55:44 Updated by Shannon Deminick 22 Mar 2013, 20:00:34

when updating the dictionary, the cache does not get refreshed in load balanced environments therefore any updates made to the dictionary will not be reflected on other servers until the app domain is restarted on each server.

Comments

Steven Lemmens 22 Mar 2013, 17:35:28

I have an idea what could be the problem here. We have a similar problem where we develop our umbraco websites locally and then upload to a server.

If we create a dictionary item locally, and then upload the macro that uses the dictionary item, we would notice that the dictionary item isn't shown.

I guess this is because locally, our cache got refreshed after adding the dictionary item. The server on the other hand has no way of knowing it should refresh its cache, so it tests if there is a cache using "EnsureCache()", which there is, so it tries to retrieve the item, which isn't found because it isn't cached yet.

Now, the question is how do you go about solving this ... Perhaps query the database on a cache miss ...


Shannon Deminick 22 Mar 2013, 17:39:21

Normally when you publish to your live site you'd refresh the app pool, then you wouldn't need to worry about that. I'm not sure what you mean by: "If we create a dictionary item locally, and then upload the macro that uses the dictionary item, we would notice that the dictionary item isn't shown." - are you sharing the database between your local environment and your published one ?


Steven Lemmens 22 Mar 2013, 17:43:33

Yes, we are sharing the database in certain instances ... So it's in the database, but not in the cache on the live server.


Shannon Deminick 22 Mar 2013, 17:46:56

I'd probably recommend to not share the live database with your development, that is a pretty specialized setup that would be very difficult to support. You will have problems with much more than just dictionary caching if you are doing this. The only way for all servers to be notified of cache changes is to setup load balancing and add each server to the list in the configuration. Otherwise you'll need to reset the app pool on the live server to ensure your 'local' changes are reflected.


Steven Lemmens 22 Mar 2013, 17:56:37

I think the only good way to solve this is:

  1. check if there is a cache
  2. try to use cache.
  3. is item found? Yes? Good
  4. no? Try to retrieve it through the db. Succeeded? That means you need to refresh the cache.
  5. no? Then it's really not there.

And this fix should be applied to every kind of cache (Content, Dictionary, ...)


Shannon Deminick 22 Mar 2013, 17:59:19

We're in the painful process of streamlining cache and making it consistent. It is proving to be very tedious. I agree that cache needs to be handled very differently moving forward but we need to take baby steps here :)


Steven Lemmens 22 Mar 2013, 18:04:06

Nice to hear you're working on it. If you want, I could up a simple solution like this?


Shannon Deminick 22 Mar 2013, 18:07:31

the code for cache handling will be changing quickly over the next few pushes so I'd wait until we finish streamlining how this all works. Eventually all cache handling will be done through the ApplicationContext.Current.ApplicationCache. Currently that is just a helper to access the HttpRuntime cache but it will be extended to support all sorts of cache (in memory, static, runtime, etc...) and will automatically support callbacks to lookup from the source if there is a cache hit miss.


Shannon Deminick 22 Mar 2013, 20:00:15

This is fixed in revision ff07b46066cd - the fix only pertains to ensuring that cache is refreshed on all distributed servers that are configured for load balancing.


Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 4.8.0, 4.9.0, 4.10.0, 4.11.0, 6.0.0, 4.9.1, 4.11.1, 4.11.2, 4.11.3, 4.11.4, 6.0.1, 4.11.5, 6.0.2

Due in version: 6.1.0

Sprint:

Story Points:

Cycle: