Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 185059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:24:11+00:00 2026-05-11T15:24:11+00:00

We have a website that runs on two load balanced servers. We use the

  • 0

We have a website that runs on two load balanced servers. We use the ASP.Net caching to help improve performance by caching high usage data. BUT, occasionally that data changes. When it does, we need to clear the relevant cache items on BOTH the load balanced servers. Does anyone have some easy to implement suggestions for how this can be done?

I know that there is software out there to manage this for you (Microsoft Velocity for one). I also know that there are other options for having separate state servers etc. However, for what we want they all seem like overkill. Just a simple mechanism for clearing out specific cache items across servers is all we need for now.

Thanks for any suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:24:12+00:00Added an answer on May 11, 2026 at 3:24 pm

    We use a simple web service approach. Our cache clear mechanism checks a web config setting to see if any other servers exist and calls the web service on those server(s) asynchronously.

    We store data with specific naming convetions to make it easy to clear what we want. So we pass in either a prefix or postfix for the item to be removed as sometimes it might be user specific (ex. the userid is appended to the name of the item) or application specific (ex. the prefix of the item is the application name).

    Here is a VB example of the ClearItem routine that would be called on either one of your nodes:

    Public Shared Sub ClearItem(ByVal strPrefix As String, ByVal strPostfix As String)      If WebConfig.Caching_Enabled() Then          ' Exit if no criteria specified '         If IsNothing(strPrefix) AndAlso IsNothing(strPostfix) Then             Exit Sub         End If          ' At the very least we need a Postfix '         If Not IsNothing(strPostfix) AndAlso Not strPostfix.Length.Equals(0) Then             _ClearItem(strPrefix, strPostfix)         End If          If WebConfig.Caching_WebFarmEnabled() Then             ' Now clear the cache across the rest of the server farm '             _ClearItem_WebFarm(strPrefix, strPostfix)         End If      End If  End Sub  Private Shared Sub _ClearItem_WebFarm(ByVal strPrefix As String, ByVal strPostfix As String)      If WebConfig.Caching_WebFarmEnabled() Then          ' Use a web service on each server in the farm to clear the '         ' requested item from the Cache '          ' Determine which servers need to remove cache items '         Dim arrServers As String()         arrServers = Split(WebConfig.Caching_WebFarmServers(), '|')          Dim strServer As String ' Holds which server we are currently contacting '           ' Loop through all the servers and call their web services '         For Each strServer In arrServers              Dim WS As New WebServiceAsyncCall             WS.StartCallBack(strServer, strPrefix, strPostfix)          Next      End If  End Sub  Private Shared Sub _ClearItem(ByVal strPrefix As String, ByVal strPostfix As String)      If WebConfig.Caching_Enabled() Then          ' Determine how we are comparing keys '         Dim blnPrefix, blnPostfix As Boolean          If strPrefix.Length.Equals(0) Then             blnPrefix = False         Else             blnPrefix = True         End If          If strPostfix.Length.Equals(0) Then             blnPostfix = False         Else             blnPostfix = True         End If          ' Reference the Cache collection '         Dim objCache As System.Web.Caching.Cache = HttpContext.Current.Cache          ' Exit if the cache is empty '         If objCache.Count.Equals(0) Then             Exit Sub         End If          ' Clear out the cache for all items matching the input(s) (on this local server) '         Dim objCacheEnum As IEnumerator = objCache.GetEnumerator()         Dim objCacheItem As Object         Dim objCurrentKey As System.Collections.DictionaryEntry         Dim strCurrentKey As String          ' Enumerate through the cache '         While objCacheEnum.MoveNext()              objCurrentKey = CType(objCacheEnum.Current, DictionaryEntry)             strCurrentKey = objCurrentKey.Key.ToString()              ' How are we comparing the key? '             If blnPrefix AndAlso Not (blnPostfix) Then ' Only by PREFIX '                  If strCurrentKey.StartsWith(strPrefix) Then                     ' Remove it from the cache '                     objCacheItem = objCache.Remove(strCurrentKey) ' Returns a reference to the item '                     objCacheItem = Nothing ' Need to explicitly nuke this because the objCache.Remove() above doesn t destroy '                 End If              ElseIf Not (blnPrefix) AndAlso blnPostfix Then ' Only by POSTFIX '                  If strCurrentKey.EndsWith(strPostfix) Then                     ' Remove it from the cache '                     objCacheItem = objCache.Remove(strCurrentKey) ' Returns a reference to the item '                     objCacheItem = Nothing ' Need to explicitly nuke this because the objCache.Remove() above doesn t destroy '                 End If              ElseIf blnPrefix AndAlso blnPostfix Then ' By both PREFIX and POSTFIX'                  If strCurrentKey.StartsWith(strPrefix) AndAlso strCurrentKey.EndsWith(strPostfix) Then                     ' Remove it from the cache '                     objCacheItem = objCache.Remove(strCurrentKey) ' Returns a reference to the item '                     objCacheItem = Nothing ' Need to explicitly nuke this because the objCache.Remove() above doesn t destroy '                 End If              Else                 ' Not comparing prefix OR postfix? Why bother continuing then! '                 Exit Sub             End If          End While      End If  End Sub 

    You can see that the code above calls other server(s) by using this helper class:

    Private Class WebServiceAsyncCall      Public Sub StartCallBack(ByVal strService As String, ByVal strPrefix As String, ByVal strPostfix As String)          ActiveWebServiceCounter += 1          Dim clearCacheProxy As New CacheClearService.CacheClear ' This is the web service which of course will exist on the other node as well '         clearCacheProxy.Url = strService          AddHandler clearCacheProxy.ClearItemCompleted, AddressOf DoneCallBack          clearCacheProxy.ClearItemAsync(strPrefix, strPostfix)      End Sub      Public Sub DoneCallBack(ByVal sender As Object, ByVal e As CacheClearService.ClearItemCompletedEventArgs)          ActiveWebServiceCounter -= 1          If e.Result.Length > 0 Then ' Something failed '             ' Log the error '         End If      End Sub  End Class 

    The web service on the remote server then calls the same code that the _ClearItem called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 163k
  • Answers 163k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Create a new website in IIS and linking to it.… May 12, 2026 at 12:09 pm
  • Editorial Team
    Editorial Team added an answer This is just a rough sketch but should be pretty… May 12, 2026 at 12:09 pm
  • Editorial Team
    Editorial Team added an answer In Postgres 8.4 (and I believe 8.3 as well), the… May 12, 2026 at 12:09 pm

Related Questions

We currently have an inventory management system that was built in-house. It works great,
OK, so I have a very large multi-threaded unmanaged c++ application (server) that runs
We have an ASP.NET website in production that generates a report and sends it
I have an existing website that uses the same code base, but is deployed

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.