I need at some point to load(from a database) a set of texts(~10 000 texts) in a specific language of my website, to then display the website.
Should I be doing this each and every time I'm displaying an element, and this would require a lot of connection attempts? Should I load the whole text once, and pass it as an argument then to the sub-elements that require it?
I was opting for a singleton class approach(load all once, then access specific element whenever needed), but it looks like this is not a good answer.
if you specifically want to cache this 1 result, maybe make it a function with a static variable for caching?
string getEnglish() {
static string ret = "";
if (ret == "") { /*actually get the data from db, and put it in ret*/ }
return ret;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.