We’ve all been there. We’ve got this immaculately designed and orchestrated site built out and ready to show to a client. It’s beautiful, it's intuitive…and it takes 30 seconds for the page to load. That’s not good! Thankfully, Episerver provides some great things to help out of the box. This makes it easy to implement the strategies we’ve mentioned in the past and allows for other methods to help in improving page speed performance.
Welcome to the easy world where Episerver automatically implements the caching of objects tied to page and block types. Any property that is maintained via the Episerver editor interface is already cached and updated as-needed by the system. No special help needed there for you!
Turns out, static file caching is already setup, enabled, and controlled via configuration settings in your application. You can manually determine the expiration time for any static file. Details can be found on the Episerver World site.
Calculated fields are those things that are determined or calculated at run time. Generally, it’s a good idea to avoid using calculated fields in Episerver page definitions. Instead, I would recommend using ViewModels for any calculated field. This helps you separate your concerns and more easily triage any errors that pop up. In the case of most calculated fields, implementing a caching strategy to handle those calculated fields. This can really help with page load and page speed issues. This is even true when you’re using default Episerver APIs. Here’s an example:
private EPiServer.IContentRepository _contentRepository = ServiceLoca-tor.Current.GetInstance();
private IEnumerable FindReferences(PageData page)
{
string cacheKey = string.Format("FindReferences:{0}", page.ContentLink.ID);
IEnumerable pageReferences;
if (!_objectCache.TryGet<ienumerable>(cacheKey, ReadStrategy.Wait, out pag-eReferences))
{
var references = _contentRepository.GetReferencesToContent(page.ContentLink, true).ToList();
pageReferences = references.Select(x => _contentRepository.Get(x.OwnerID));
_objectCache.Insert(
string.Format(cacheKey, page.ContentLink.ID),
pageReferences,
new CacheEvictionPolicy(new TimeSpan(10), CacheTimeoutType.Absolute)
);
}
return pageReferences;
}
Page speed in Episerver turns out to be easy. The default CMS provides excellent caching around user managed entries and with some simple caching steps, you can increase even the most troublesome pages with calculated fields.