保持一个月汇率稳定的最佳实践
我想在我的应用程序中使用汇率,但我不想从网络服务获取这些汇率。
我只是想将其保存在某个地方
并从那里读取它,并且我希望能够逐月更新该费率。
我可以轻松地将数据保存在数据库中,但因为我会经常使用该速率,所以可能会导致开销,不是吗?
我不确定,但我可能会将其保留在 XML 中,但我不确定它与数据库方法有何不同。
我可能会将其保留在代码中作为硬编码,这绝对是最快的,但我无法轻松更新它。
进行此类操作的最佳实践是什么?
I want to use exchange rates in my application but I do not want to get these rates from a web service.
I just want to keep it in somewhere
and read it from there and I want to be able to update that rates month by month.
I may keep data in database easily but because I will use that rates often it may cause to overhead, doesn't it?
I am not sure but I may keep it in XML but I am not sure how it differs from database approach.
I may keep it in the code as hardcoded, definetly the fastest, but I couldn't update it easily.
What is the best practices for doing such operation ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将数据存储在一些易于阅读的文件中(例如,如果您使用 Java,则为属性文件。如果您习惯使用 XML,则为 XML,等等)。
当您更新货币时,写出该文件。当您的应用程序启动时,加载文件并将其保存在内存中。
您谈论的是微不足道的数据量,因此通过一些简单的缓存(即读取文件一次并在应用程序运行时存储和维护应用程序),您不会注意到任何实际的性能影响。
Store the data in some easy readable file (Properties file if you're using Java, for example. XML if you're comfortable with it, whatever).
When you update the currencies, write the file out. When your app starts up, load the file and keep it in memory.
You're talking a trivial amount of data, so with some simple caching (i.e. read the file once and store and maintain the app as long as its running), you won't notice any real performance impact.
在你的情况下,我可能会使用 XML 或 Json 文档。更简单,更容易维护。
In your case I would probably use XML or Json document. Simpler and easier to maintain.