Sliding expiration of localized ASP.NET resources

2019-05-25 18:54发布

Assume that we have 2 sites myDomain.AU and myDomain.RU having the same code and localized resource files *.resx and *.ru.resx. We expected that most of English users will use AU site and most of Russian users will use RU site. However if some user of AU domain will request Russian version, .Ru resources will be loaded on AU server and Russian language will be shown.

But I don’t want to keep .RU resources until recycle of the pool, but want to unload them if no one use them. So I want to have timing expiration of cached localized resources with configured time of expiration for each language. Related question was raised at http://techsoda.wordpress.com/2008/01/04/aspnet-reset-that-resource/ and http://forums.asp.net/t/1201065.aspx/1

Rick Strahl in “Creating a Data Driven ASP.NET Localization Resource Provider and Editor”( http://www.west-wind.com/presentations/wwdbresourceprovider/ ) has DbResourceConfiguration.ClearResourceCache() , that clears all cache, but not expired only.

Any suggestions, references what is the best way to implement it are welcome.

UPDATE: Rick’s comment below pointed me, that I am doing “Premature Optimization”. Anyway it will be good to know a solution, if loading of too many resources will become a problem in production.

1条回答
不美不萌又怎样
2楼-- · 2019-05-25 19:57

Instead of using a static dictionary as the resource cache (as in Rick Strahl's sample) why not store the individual culture data in the ASP.NET cache, which implements sliding expiration out of the box?

查看更多
登录 后发表回答