Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce database hits in linq to sql

I have a scenario and i want to know bestpractices to reduce database hits. Scenario is I have a dictionary table in my application where i put all the words/keywords for translation purpose because my system is multilingual. Keywords are placed all over the page they can be 10 to 20 in one page and on each word it fetches the translation from database if user in not viewing english version of website.

My application in on Asp.Net MVC 2 with C# and LINQ2SQL.

like image 589
Fraz Sundal Avatar asked Nov 29 '22 15:11

Fraz Sundal


2 Answers

Caching is a good way to reduce database queries. There are 2 levels of cache you could use:

  • Cache objects (for example results of database queries)
  • Cache HTML output of entire controller actions or partials
like image 118
Darin Dimitrov Avatar answered Dec 16 '22 21:12

Darin Dimitrov


The translation typically don't change very often and the amount of data is limited. Read up all translated strings when the web app is started and put them in a globally accessible Dictionary. Whenever you need the translated strings, look them up in the dictionary.

like image 26
Anders Abel Avatar answered Dec 16 '22 21:12

Anders Abel