question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to remove cache compile template when run CompileRenderAsync

See original GitHub issue

I can’t remove cache template after run method CompileRenderAsync My case is: Step 1: run resultHtml = await _razorLightEngine.CompileRenderAsync(templateId, htmlTemplate, obj);

When I change htmlTemplate to new value template and run this method again (Step 2), but this still return value that ran in Step 1

htmlTemplate is string template

So, how can I remove cache to get the new value follow htmlTemplate Thank you.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:16

github_iconTop GitHub Comments

1reaction
reponemeccommented, Feb 16, 2023

What do you mean by “turning on compiled template caching”? I would also be interested in that. I think UseMemoryCachingProvider() or UseCachingProvider() extensions only affect page template cache, not RL’s private compiled metadata template cache which is the crux of the problem.

0reactions
Fosolcommented, May 15, 2023

Is there any update related to invalidating or overwriting a cached template? This doesn’t work.

        var key = $"report_{report.Id}_subject";
        var cache = this.RazorEngine.Handler.Cache.RetrieveTemplate(key);
        var model = new TemplateModel(content, this.Options);

        if (!updateCache && cache.Success)
            return await this.RazorEngine.RenderTemplateAsync(cache.Template.TemplatePageFactory(), model);
        else
        {
            return await this.RazorEngine.CompileRenderStringAsync(key, report.Settings.GetDictionaryJsonValue<string>("subject") ?? "", model);
        }
Read more comments on GitHub >

github_iconTop Results From Across the Web

RazorEngine un-cache compiled templates
EDIT: I have just read a bit about how the caching works and that if the same name is passed in with a...
Read more >
Clear template cache from the CLI?
I was looking for a way to clear the “template caches” and “compiled templates” from the CLI, as I want to automatically do...
Read more >
RazorLight
Use Razor to build templates from Files / EmbeddedResources / Strings / Database or your custom source outside of ASP.NET MVC. No redundant...
Read more >
Old copy of template is running - how do I clear the cache?
How do I clear the cache or force a rebuild of the cache?> the cache key used for storing the compiled template is...
Read more >
Using Razor Templates without MVC (RazorLight)
// First create engine. var engine = new RazorLight.RazorLightEngineBuilder() . ; // Try to find template. var found = engine.TemplateCache.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found