July 15, 2024

Hello Sitecore Family,

Recently, we were doing a POC of upgrading a Sitecore solution from Sitecore 7.0 to Sitecore 8.0 and while moving there (as in, not InPlace upgrade but by Migrating to new instance), we were doing a number of foundational tasks – like, upgrading  the .Net framework to 4.5, upgrading ASP.NET version to 5.1, upgrading Glass Mapper to and some others.


Now this solution we have is a multisite Sitecore solution and after upgrading a pretty basic website project with the above mentioned assemblies, we found that a couple of locations were showing images from some other site! weird.

We later found, that whichever site was loaded first, that image got loaded and that image was shown on other sites of the similar structure.


Oh but it was a simple Glass Mapper Html Helper, how can it lead us to caching issue?

[code language=”csharp”]
@Html.Raw(GlassHtml.RenderImage(Model, x => Model.Logo, null, true))


With all these questions, I contacted Mike Edwards. — Oh well, I first contacted Mark Stiles by mistake and explained him every bit of the issue I faced — Bummer!


Firstly, thanks to Mike Edwards for being approachable on Slack chat and giving a solution to the problem that we had. Glass Mapper is really well documented, and that’s where the solution was:


Quoting Mike Edwards here:

If you have written your lambda expression with reference to the Model as you have in your example you will need to turn off the lambda cache.

That’s what we did and bingo, the error was solved!

What we did?

We added the following code in the method called CreateResolver in the class GlassMapperScCustom in App_Start folder:

[code language=”csharp”]
config.UseGlassHtmlLambdaCache = false;


A small suggestion Mike,  documentation is great but search is good to have on Glass Mapper site. 🙂

Happy Solving Caching Issues! 🙂

2 thoughts on “Solution for Caching issue if Lambda Expression used with Glass Mapper Models

Leave a Reply

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