We have a registration type system that sends a confirmation email by completion. Within a few minutes, the system had about 3,000 registrations, and we noticed an error. If user A registers several ms after registration by user B, user A will receive information about user B by e-mail. We managed to fix this problem, and I narrowed it down to this piece of code, which receives the email template from the cache and simply replaces the line on the place holder.
private string ProcessEmailBody(MyRegistrationModel registration) { var content = CacheHelper.GetContent("REGISTRATIONEMAIL"); if (content != null) { content.Text = context.Text.Replace("@@ FULL_NAME@ @", registration.FullName); return content.Text; } else return null; }
The CacheHelper.GetContent() method is static, and I fixed this "error" by doing the following:
private string ProcessEmailBody(MyRegistrationModel registration) { var content = CacheHelper.GetContent("REGISTRATIONEMAIL"); if (content != null) { string body = content.Text; body = body.Replace("@@ FULL_NAME@ @", registration.FullName); return body; } else return null; }
And I canβt understand all my life why this solved the problem. Can anyone shed some light on this?
EDIT : here is my GetContent () method (I know the signatures are different from the previous ones, I was brief)
public static Content GetContent(string key, int partnerSiteId, int? version, IContentRepository contentRepository, out string cacheKey) { cacheKey = string.Format("{0}_{1}_{2}", key, partnerSiteId, version); var content = CacheManager.Get(cacheKey, () => contentRepository.GetContent(key, partnerSiteId, version), WebConfig.GetCacheDuration(CacheProfile.Short)); return content; } private static DataCache _Cache = null;
contentRepository.GetContent just goes into the database and returns the actual content back.