The Pit Answer is correct; each machine still has its own IP address. I use the ASHX handler to receive requests to reset the cache. Any computer in a web farm can initiate a request.
This is a fairly complete example, but there are some helper methods and configuration settings that I have not included.
<add key="UserServers" value="http://123.456.789.001/|http://123.456.789.002" />
Here is the code to actually call the handler on each site that executes the reset cache. I suggest using some kind of common password between the machines and separately protecting the handler so that it cannot be accessed publicly.
public static void ClearAllUserCaches()
{
ClearUserCaches();
string[] urls = AppSettings.UserServers;
for( int i = 0; i < urls.Length; i++ )
{
string url = urls[i] + AppSettings.UserCacheResetPath + "&sharedPassword=" + AppSettings.SharedPassword;
WebRequest request = null;
HttpWebResponse response = null;
try
{
request = WebRequest.Create( url );
response = (HttpWebResponse)request.GetResponse();
}
catch( WebException ex )
{
Log.LogException( ex );
}
finally
{
request = null;
}
if( response == null || response.StatusCode != HttpStatusCode.OK )
{
if( response != null )
{
response.Close();
response = null;
}
}
}
}
The handler code itself (sorry for the length).
public class AdministrationRequestHandler : IHttpHandler
{
public void ProcessRequest( HttpContext context )
{
string action = context.Request.QueryString["action"].ToSafeString().ToUpper( CultureInfo.InvariantCulture );
if( string.IsNullOrEmpty( action ) )
{
context.Response.Write( "Missing action." );
return;
}
string sharedPassword = context.Request.QueryString["sharedPassword"].ToSafeString();
if( string.IsNullOrEmpty( sharedPassword ) )
{
context.Response.Write( "Missing shared password." );
return;
}
if( sharedPassword != AppSettings.SharedPassword )
{
context.Response.Write( "Invalid shared password." );
return;
}
if( action == "CLEAR_CACHE" )
{
AppContext.ClearUserCaches();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
source
share