PageTypeBuilder doesn’t cache

This is a PageTypeBuilder specific post, so it does not apply to users of CMS 7+.

This post balances yesterday’s post which discusses the effects of caching. This one discusses the effects of not caching.

Consider the following code example:

See the class variable  _displayPageName? The variable that stores the value retrieved from the first non-null property of DisplayPageName and PageName. From reading that code, most readers would assume that the GetPropertyValue method is infrequently called.

Unfortunately, that is an incorrect assumption and the cache is practically useless. This is because the strongly typed PageData instances generated by PageTypeBuilder are never cached. Each time you get this page from the DataFactory, its class variables reset to their default values.

PageTypeBuilder hooks into Episerver CMS by attaching a handler to the DataFactory.Loaded*-events. Each time an untyped page is loaded from the cache, the LoadedPage event is fired and this line of code is executed:

The returned page instance is a new instance, with its properties populated by a cached instance. In the best of circumstances, the cache would be operational only for the duration of one page view, but I doubt it even works that well.

Leave a Reply

Your email address will not be published. Required fields are marked *