How to save template in cache? #484
Replies: 2 comments
-
I know it's been a while since you posted. I had the same issue as you did while I was attempting to populate emails with razor templates as part of a foreach loop. RazorLight should be creating the cached template when calling CompileRenderStringAsync(). My issue was that I instantiated the engine inside of the loop, so a new instance was being created each time which did not have access to the previous cache. Maybe it's possible that was happening to you? By instantiating before the loop, each iteration then had access to the cache. With caching the outcome was 60X faster than before! Hope that helps if anyone else has the same issue. |
Beta Was this translation helpful? Give feedback.
-
Yes, thew problem is that in the controller class the object was recreated on every call, so the cached value was lost. I actually had my own wrapper object, so I added the RazorLight object as a static member and it took care of the issue. See #493 |
Beta Was this translation helpful? Give feedback.
-
The README example shows how to render template from cache, but how do you add it to cache? I.e. what should happen if the
cacheResult.Success
isfalse
?Here is my code outline (my templates come from strings):
The code never gets into the
if (cacheResult.Success)
block. What am I doing wrong or not doing at all?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions