private static void WriteTemplateCacheForLocale(string locale)
        {
            bool isCurrentLocale = string.IsNullOrEmpty(locale) &&
                                   string.IsNullOrEmpty(EngineEnvironmentSettings.Host.Locale) ||
                                   (locale == EngineEnvironmentSettings.Host.Locale);

            IDictionary <string, ILocalizationLocator> locatorsForLocale;

            if (string.IsNullOrEmpty(locale) ||
                !_localizationMemoryCache.TryGetValue(locale, out locatorsForLocale))
            {
                locatorsForLocale = null;
            }

            List <TemplateInfo> existingTemplatesForLocale = LoadTemplateCacheForLocale(locale);

            if (existingTemplatesForLocale.Count == 0)
            {
                // the cache for this locale didn't exist previously. Start with the neutral locale as if it were the existing
                existingTemplatesForLocale = LoadTemplateCacheForLocale(null);
            }

            HashSet <string>    foundTemplates     = new HashSet <string>();
            List <TemplateInfo> mergedTemplateList = new List <TemplateInfo>();

            foreach (TemplateInfo template in NewTemplateInfoForLocale(locale))
            {
                mergedTemplateList.Add(template);
                foundTemplates.Add(template.Identity);
            }

            foreach (TemplateInfo templateInfo in existingTemplatesForLocale)
            {
                if (!foundTemplates.Contains(templateInfo.Identity))
                {
                    UpdateTemplateLocalization(templateInfo, locatorsForLocale);
                    mergedTemplateList.Add(templateInfo);
                    foundTemplates.Add(templateInfo.Identity);
                }
            }

            SettingsLoader.WriteTemplateCache(mergedTemplateList, locale, isCurrentLocale);
        }