简体   繁体   中英

ASP.Net server side data caching on a web farm

Scenario:

Implement in-memory caching of master data in the WCF layer of an ASP.Net application for a web farm scenario

  1. Data is cached on first access to the service layer 's, say, GetCountryList() method with cache' expiry set to midnight. Let's say the cache key is “CountryList_Cache”
  2. All subsequent requests are served through cache'
  3. If the Country list is updated using the master screen, then an additional call is made to invalidate the “CountryList_Cache” and fresh data is loaded into it
  4. The next call now receives the updated country list The above step is easy in a single server scenario, as step 3 only requires a cache expiry call to one server. The complexity increases when we have 2 or 3 load balanced web servers, because in that case the cache is updated (via master screen) on only one of the servers but has to be invalidated on all 3 servers.

Our proposed solution:

We intend to have an external service/ exe/ web page which would be aware of all load balanced servers (via a configuration file). In order to invalidate a specific cache, we would invoke this external component which in turn would invalidate the respective cache key on all the web servers and load then cache with latest data.

The problem:

Although the above approach would work for us, we do not think it is a clean approach for an enterprise class LOB application. Is there a better/ cleaner way of achieving the cache expiry across multiple servers?

Note:

  1. We do not want to use distributed caching due to the obvious performance penalty, as compared to in-proc/ in-memory cache
  2. Caching has been implemented using System.Runtime.Caching
  3. We have worked with SQL dependency and used it in scenario of single web server

Comparing your design to Windows Azure In-Role Cache and AppFabric Cache.

In those products, the cache is stored in one or more servers (cache cluster). In order to speed up requests, they created Local Cache .

When local cache is enabled, the cache client stores a reference to the object locally. This local reference keeps the object active in the memory of the client application. When the application requests the object, the cache client checks whether the object resides in the local cache. If so, the reference to the object is returned immediately without contacting the server. If it does not exist, the object is retrieved from the server. The cache client then deserializes the object and stores the reference to this newly retrieved object in the local cache. The client application uses this same object.

The local cache can be invalidation by time-out and/or notification

Notification-based Invalidation

When you use cache notifications, your application checks with the cache cluster on a regular interval to see if any new notifications are available. This interval, called the polling interval, is every 300 seconds by default. The polling interval is specified in units of seconds in the application configuration settings. Note that even with notification-based invalidation, timeouts still apply to items in the local cache. This makes notification-based invalidation complementary to timeout-based invalidation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM