Problems with merging and caching MVC

I am using System.Web.Optimization with an MVC 4 application that is hosted on a farm behind some loadbalancers. There are some clients that access this network through a proxy server for caching on their side. We do not control their proxies.

MVC binding is smart because it adds the ur parameter v = {hash} behind the script link, which is unique to the bundled files. Thus, whenever a file in a package changes, the hash changes, and the file is again requested.

The question is: how can I prevent package delivery if this hash does not match the current files?

Normal deployment process:

  • take server 1 from load balancing
  • update server 1
  • test materials on the server 1
  • return server 1 to the farm
  • Rinse and repeat with all other servers in the farm, one at a time

In the last collision, a problem arises: Say server 1 and 2 are already updated, server 3 is currently being updated (and this is not in the farm), and server 4 through 8 has not yet been updated.

Now there is a chance of approx. 1/4, server 1 or 2 responds to the request. Both of them have new scripts, and therefore their hash behind the package URL is different from the hash that the server 4-8 uses.

However, there is a chance to get closer. 3/4, that the next request to this script with a hash for the updated one is uploaded to one of the servers that have not yet been updated. Although the hashe in the url parameter does not match the earlier contents of the file, the package still comes with the old contents. This is bad for this particular customer.

In our scenario with a more complex scenario, the client-side proxy now caches the old script under a new URL with a new hash, which will cause this problem to be transferred to all other clients behind this cache.

How can I talk about the set, respond to requests with the wrong hash from 404 so that the wrong contents are not cached?

+4
source share
1 answer

Currently, the hash is used only for caching the bust on clients. The server completely ignores this and will simply serve the packet.

The good news is that the client cannot cache the โ€œwrongโ€ version of the package, because we calculate the hash of the package using the actual contents of the package. Therefore, if your servers still have mixed / outdated versions of the files, the hash will change when it is finally updated.

Unfortunately, I do not have a good workaround, since you can avoid this situation, given that you have a farm with servers - these are different states.

0
source

All Articles