LazZiya / XLocalizer

Localizer package for Asp.Net Core web applications, powered by online translation and auto resource creating.
https://docs.ziyad.info
128 stars 14 forks source link

Similar keys that are stored in different resources caching the same value #13

Closed LazZiya closed 3 years ago

LazZiya commented 3 years ago

ExpressMemoryCache is caching key-value pairs in memory for fast access. But when we have similar keys with different translations that are stored in different resource files only one value is stored in memory.

e.g.: Suppose we have below localization resources:

And we have the below key-value pairs in both resources:

ExpressMemoryCache will store only first key-value, and when IStringLocalizer is called for the second resource, it will retrive the value from cache that is stored for the first resource.

IStringLocalizer<AdminResource> _loc1;
IStringLocalizer<AdminResource> _loc2;

// UseExpressMemoryCache = true
_loc1["Welcome"] // output: Welcome admin
_loc2["Welcome"] // output: Welcome admin

// UseExpressMemoryCache = false
_loc1["Welcome"] // output: Welcome admin
_loc2["Welcome"] // output: Welcome user
LazZiya commented 3 years ago

fixed with 73b7924