0

Caching your data in your application code is generally a good idea for many reasons. We have being doing this for quiet some time in our shared environment which includes ColdFusion, .NET, and PHP. However, because we share this environment with many other development groups in our organization, there is significantly more downtime then we (or our customers) appreciate.

Therefore, our web admins are moving to implement a new environment. In this environment they are adding a QA level between the current Dev and Prod environments. Also, to increase uptime, they are clustering machines at both the QA and Prod level.

This is all great for many reasons. The one area where I see a problem is with caching. There will be two (or more depending on the number of nodes) sets of cache. As you can imagine, this creates the following potential problem. Cache is the same on node A and B. User 1 updates data and thus cache is updated on node A. User 2 comes to query data but is on node B and therefore get's the old data.

Are their any best practices on how to handle this?

Is there any type of change I can make in my code?

Are there server settings that can be implemented?

Jason
  • 145
  • 5

2 Answers2

2

You don't say exactly what is being cached or how, so we'll be shooting in the dark a little bit.

A typical clustered cache solution will take care of ensuring that all members of the cluster have a consistent view of the data. For example, memcached is a common solution to application data caching, and an update from one cluster member will immediately be visible to other cluster members.

If you are caching generated web pages, the solution is usually to only cache data that is either invariant or that has well defined expiration times. Data that differs per request is often not cached. This gives web application a performance boost because fetches for common items like images, stylesheets, and javascript can come from the cache while custom user HTML is pulled from the backend. Alternatively, some solutions can invalidate the cache if the data used to generate a page has changed.

larsks
  • 43,623
  • 14
  • 121
  • 180
0

Do you know exactly how this clustering is being done? For example, if you're "clustering" your web servers by sticking a group behind a hardware load balancer, the clients will maintain their connection to a single backing server, so there will be no caching issues.

phoebus
  • 8,380
  • 1
  • 31
  • 30