开发者

Is it advisable to store things such as list of cities on the db?

开发者 https://www.devze.com 2022-12-29 00:30 出处:网络
Hi I\'m using CakePHP and开发者_如何学运维 I\'m wondering if it\'s advisable to store things that don\'t change a lot in the database lik the list of cities?If your application already needs a databas

Hi I'm using CakePHP and开发者_如何学运维 I'm wondering if it's advisable to store things that don't change a lot in the database lik the list of cities?


If your application already needs a database, why would you keep data anywhere else?

If the list doesn't change (per installation) and it's reasonably small and frequently used, then it might be worth reading it once on initialization and caching the result to improve performance and reduce the load on the database.


You get all sorts of queries and retrievals out of the box, the same way you access any other of your data. Databases are as cheap as flat files today, but you get a full service.


I see this question has had an answer accepted - I still want to chime in with my $0.02

The way I typically do for arrays of static data (country list, timezone list, immutable sets you would use enum for...) is to use this array datasource.

It allows you to map relationships between db models and array based models and to use the usual find syntax / Containable on the relationships.

http://github.com/jrbasso/array_datasource


If it is pretty much a static list, then you can store it either in the db or a file, but keep it in memory for use. In other words, load it once whether from db or file. What you don't want to do is keep taking a hit loading it. Especially if you use it on most page views. Those little bits of time add up if you have a large number of visitors.

The flip side, of course, is if you find yourself doing this for large lists or lots and lots of little lists. Then you could run into problems of keeping too much in memory.

Bill the Lizard is right about it being important whether or not the list links to other tables. If it does, then you will need it in the db if you need queries that will include it.

0

精彩评论

暂无评论...
验证码 换一张
取 消