简体   繁体   English

使用yml作为数据引用。 馊主意?

[英]Using yml as a data reference. Bad idea?

I need about 1,000 words to be able to be accessed constantly by my app. 我需要大约1000个单词才能通过我的应用程序不断访问。 The reason I want it detached is so that down the line, I can dynamically change what those 1,000 words will be. 我希望它分离的原因是,我可以动态地改变这1000个单词的内容。

But I don't necessarily feel this requires a database injection. 但我不一定觉得这需要数据库注入。 I feel a simple .yml file could work. 我觉得一个简单的.yml文件可以工作。

Is this a good practice? 这是一个好习惯吗? And if it is, what would be the best way to do this? 如果是,那么最好的方法是什么?

Is it ok to load the 1,000 words in a before_filter call ? 可以在before_filter调用中加载1,000个单词吗?

Don't think that architecturally this is the right call. 不要认为这在建筑上是正确的。

If those are to be changed rarely, then you can put them inside a constants class. 如果要很少更改它们,那么可以将它们放在常量类中。 If you plan to change them often, what you will do is write to file system and read from it which is exactly what every database does, but in a much much faster and optimal way then you could possibly write. 如果您打算经常更改它们,那么您将要写入文件系统并从中读取这正是每个数据库所做的事情,但是以更快更好的方式然后您可以编写。

My two cents. 我的两分钱。 Let us know how it worked out. 让我们知道它是如何运作的。

Do not use relational database unless you really need to. 除非你真的需要,否则不要使用关系数据库。 If your "words" are relatively immutable, can be accessed simultaneously without multithreadig concerns, you do not need querying etc - they are better off in some hash loaded for entire applications on startup loading them for every reuest is not a good idea. 如果你的“单词”是相对不可变的,可以在没有多线程问题的情况下同时访问,你不需要查询等 - 它们在启动时为整个应用程序加载的一些哈希值更好,为每个reuest加载它们并不是一个好主意。 ( this advice is not related to ROR ) (这个建议与ROR无关)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM