i18n performance: resx vs. database?

牧云@^-^@ 提交于 2020-01-15 06:30:06

问题


Question:

I'm asking myself whether I should use .resx files or a database to localize my ASP.NET MVC 3 application.

I use a database anyway, so there's no additional effort required for a data-access layer.

I know I can do both, but I'm a bit worried about performance...

Is it a good idea loading the DB with additional translation work, whereas this could be done by the webserver ?
Or is reading the .resx files much slower than using a database ?

Also, it seems to me that the .resx-file way is a bit inflexible.
You can assume that the db and the web-server run on the same machine.
You can also assume a Linux system with nginx as webserver, mono via fastcgi and a tuned PostGreSQL server.


回答1:


It doesn't take much effort to create an application which will pull the resources out of the database and generate a resx file. Thus giving you the flexibility and ease of maintenance of the database and the performance of resx.

I recently got this technique working for My MVC website, here are a few lnks to my questions on the subject, some of which I also answered myself with the solution.

  • "Run Custom Tool" for resx files in MVC2 project (from an external application/script)
  • Do I need the resx Designer.cs file?
  • Why am I getting App_GlobalResources assembly generated? (Error = CS0433)



回答2:


Either way, cache them in your memory using a proper data structure. Loading it into the scripts is important, not having to load them again is more important, quick lookups in the data is most important.

Depending on what you're going to do, a simple HashMap should be very fast for quick lookups for strings. Make sure to store everything in the server's memory (RAM).

i18n performance goes in two categories: loading and searching. Simply limit how many times you load, and use quick lookups. Definitely don't reload the file for each call to the i18n module, database or file.



来源:https://stackoverflow.com/questions/9402150/i18n-performance-resx-vs-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!