Always running DocumentCache trimming on IIS

Normally DocumentCache is trimmed automatically according to CacheAutoTrimInterval property, however trimming can be triggered only when your host app is actually running. Most of the time, this is sufficient:
  • if a user hits your DocumentViewer host app, trimming is active until the shutdown of the app (according to the interval property).
  • if no user is hitting your app, then trimming is not active as your app may not be actually running. If there are no users, it means no new files are being created in cache so this is acceptable for most of the time.
In case, you need DocumentCache trimming to always run for your app hosted on IIS, regardless of user activity (maybe you have constrained disk space requirements):

When an ASP.NET application is hosted on IIS, it's life is controlled by IIS. For example, IIS can kill/recycle the application pool process when the site is idle.

By default, a web application will not be started until the first user hits your site. Even more, there are some events that will bring your web application down after some time (idle Timeout and different app pool recycling events). In these cases, as the DocumentCache's recurring tasks runs inside the web application, these tasks will not be enqueued, and enqueued jobs will not be processed.

This is particularly true for smaller sites, as there may be long periods of user inactivity. However this can be changed with IIS settings. You can ensure that your web app instance is always running to guarantee the in-time background job processing.

Please ensure you do all these settings:

  1. Install the Application Initialization Module
    You can install the Application Initialization module via the Server Manager. You can find the module under Server Roles -> Web Server -> Application Developer -> Application Initialization:

  2. Configure the app pool
    In IIS Manager, right click on the application pool under which the application runs and select “Advanced Settings”. Update the following values:

  3. Configure the IIS site
    In IIS Manager, right click on the site for the application, select “Manage Website” -> “Advanced Settings” and set the “Preload Enabled” value to true:

Reference: