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 4.0.5.54 and some others.
Challenge:
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.
CACHING ISSUE! — Oh yes!
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))
[/code]
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!
Solution:
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:
http://www.glass.lu/Mapper/Sc/Documentation/GlassHtml
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;
[/code]
A small suggestion Mike, documentation is great but search is good to have on Glass Mapper site. 🙂
Happy Solving Caching Issues! 🙂
Is there a way to selectively disable cache for specific lambdas, or is {config.UseGlassHtmlLambdaCache = false} an all-or-nothing setting?
Not that I know of. Good to check on Sitecore StackExchange or Sitecore Community Slack Channel.