@@ -213,13 +213,22 @@ private bool LoadMessagesIntoCache(string langtag)
213
213
Translation t = _translationRepository . GetTranslation ( langtag ) ;
214
214
215
215
// 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 ) ;
223
232
}
224
233
return true ;
225
234
}
0 commit comments