Sitecore Application_Start and <initialize> Pipeline

For some time ago, I needed to build up some cache on Sitecore application start up. Sure, in a clean web application I could use the Global.asax, but in the world of Sitecore, the Global.asax has been made private. Instead of changing the Global.asax file, you should use the initialize pipeline. The initialize pipeline is started at application start (you find the initialize pipeline in Sitecore.config).

In this case of building up some caching on Sitecore application start, I create a new config include file and add the my new processor:
 
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
<pipelines>
    <initialize>
      <processor type="MyExtensions.Pipelines.Caching.CachePrefill, MyExtensions" xdt:Transform="Insert" />
    </initialize>
  </pipelines>
</Sitecore>
</configuration>

Do the coding. Notice, you don’t need to inherit from any other namespaces. 
namespace MyExtensions.Pipelines.Caching
{
    public class CachePrefill
    {
        public void Process(PipelineArgs args)
        { 
            Sitecore.Diagnostic.Log.Info("MyExtensions: Running CachePrefill.Process method", this);
            
            //do my magic cachePrefill();
            
            Sitecore.Diagnostic.Log.Info("MyExtensions: Done running CachePrefill.Process method", this);
        }
    }
}

Nothing more, nothing less.

No comments: