<p>Each of our production web servers maintains its own cache for separate web sites (ASP.NET Web Applications).  Currently to clear a cache we log into the server and "touch" the web.config file. </p>

<p>Does anyone have an example of a safe/secure way to <strong>remotely</strong> reset the cache for a specific web application?  Ideally we'd be able to say "clear the cache for app X running on all servers" but also "clear the cache for app X running on server Y".</p>

<p>Edits/Clarifications: </p>

<ul>
<li><p>I should probably clarify that doing this via the application itself isn't really an option (i.e. some sort of log in to the application, surf to a specific page or handler that would clear the cache). In order to do something like this we'd need to disable/bypass logging and stats tracking code, or mess up our stats.</p></li>
<li><p>Yes, the cache expires regularly. What I'd like to do though is setup something so I can expire a specific cache on demand, usually after we change something in the database (we're using SQL 2000).  We can do this now but only by logging in to the servers themselves.</p></li>
</ul>

[{'answer_id': 77158, 'author': 'Adam Weber', 'author_id': 9324, 'author_profile': 'https://Stackoverflow.com/users/9324', 'pm_score': 0, 'selected': False, 'text': '<p>This may not be "elegant", but you could setup a scheduled task that executes a batch script. The script would essentially "touch" the web.config (or some other file that causes a re-compile) for you.</p>\n\n<p>Otherwise, is your application cache not set to expire after N minutes?</p>\n'}, {'answer_id': 77860, 'author': 'Oli', 'author_id': 12870, 'author_profile': 'https://Stackoverflow.com/users/12870', 'pm_score': 2, 'selected': False, 'text': '<p>For each application, you could write a little cache-dump.aspx script to kill the cache/application data. Copy it to all your applications and write a hub script to manage the calling.</p>\n\n<p>For security, you could add all sorts of authentication-lookups or IP-checking.</p>\n\n<p>Here the way I do the actual app-dumping:</p>\n\n<pre><code>Context.Application.Lock()\nContext.Session.Abandon()\nContext.Application.RemoveAll()\nContext.Application.UnLock()\n</code></pre>\n'}, {'answer_id': 82594, 'author': 'Sean Gough', 'author_id': 12842, 'author_profile': 'https://Stackoverflow.com/users/12842', 'pm_score': 2, 'selected': True, 'text': '<p>Found a <a href="http://archive.devx.com/dotnet/articles/rj060502/rj060502-1.asp" rel="nofollow noreferrer">DevX</a> article regarding a touch utility that look useful.  </p>\n\n<p>I\'m going to try combining that with either a table in the database (add a record and the touch utility finds it and updates the appropriate web.config file) or a web service (make a call and the touch utility gets called to update the appropriate web.config file)</p>\n'}]
['https://Stackoverflow.com/questions/76855', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12842/']