I’m a little unsure of the lifetime of a template context or how I should handle my requirement. I have X clients sending Y campaigns and each campaign may have Z members. When a campaign is sending (they could be sending concurrently), the logic is straightforward:
Pseudocode. Campaigns are broken into batches of 1000. The following code would be for one batch. Campaigns could top out at 500-1000 batches:
var context = new TemplateContext().Init();
var members = GetMembers(campaignId);
var template = GetTemplate(campaignId);
foreach(var member in members) {
var templateArgs = GetCampaignArgs(campaignId, member);
var html = context.evaluateTemplate(template, templateArgs);
sendMessage(member.recipient, html);
}
Should I instantiate a new templatecontext per campaign? The example on the site uses the Virtual File system is that more performant is this pseudocode the recommended way? Thanks.
Edit: I have tested creating a new Template context for each batch and it is very fast. After dealing with Razor engine with a similar situation that was my fear as it was pretty slow. Pretty happy with the performance here.