Skip to content

Commit dea4748

Browse files
committed
FIX: performance issues related to translations in the default application language #368
1 parent d6b1213 commit dea4748

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Diff for: src/i18n/Concrete/TextLocalizer.cs

+16-7
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,22 @@ private bool LoadMessagesIntoCache(string langtag)
213213
Translation t = _translationRepository.GetTranslation(langtag);
214214

215215
// Cache messages.
216-
// NB: if the file changes we want to be able to rebuild the index without recompiling.
217-
// NB: it is possible for GetCacheDependencyForSingleLanguage to return null in the
218-
// case of the default language where it is added to AppLanguages yet doesn't actually exist.
219-
// See MessageKeyIsValueInDefaultLanguage.
220-
var cd = _translationRepository.GetCacheDependencyForSingleLanguage(langtag);
221-
if (cd != null) {
222-
System.Web.HttpRuntime.Cache.Insert(GetCacheKey(langtag), t.Items, cd); }
216+
// · In order to facilitate dynamic refreshing of translations during runtime
217+
// (without restarting the server instance) we first establish something upon
218+
// which the cache entry will be dependent: that is a 'cache dependency' object
219+
// which essentially triggers an event if/when the entry is to be considered
220+
// as 'dirty' and whihc is listened to by the cache.
221+
// In our case, we want this 'dirty' event to be triggered if/when the
222+
// translation's source PO file is updated.
223+
// NB: it is possible for GetCacheDependencyForSingleLanguage to return null in the
224+
// case of the default language where it is added to AppLanguages yet there
225+
// doesn't actually exist an underlying PO file. This is perfectly valid when
226+
// LocalizedApplication.MessageKeyIsValueInDefaultLanguage == true (default setting).
227+
// In this case the cache entry is associated with the null CacheDependency instance
228+
// which means the cache entry is effectively permanent for this server instance.
229+
System.Web.Caching.CacheDependency cd = _translationRepository.GetCacheDependencyForSingleLanguage(langtag);
230+
// · Insert translation into cache associating it with any CacheDependency.
231+
System.Web.HttpRuntime.Cache.Insert(GetCacheKey(langtag), t.Items, cd);
223232
}
224233
return true;
225234
}

0 commit comments

Comments
 (0)