参考数据模式 [英] Reference Data Pattern

查看:127
本文介绍了参考数据模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与此线程类似,但不完全相同:如何以线程安全方式缓存信息

Similar to this thread, but not exactly: How To Cache Information In A Threadsafe Manner

处理引用数据的常用模式是什么 - 应用程序经常读取的数据,通常在数据库或属性文件中外部化,但更新次数(天,周,月)?当数据被更新时,它将被外部更新。

What is the usual pattern for dealing with "reference data" - data that is frequently read by an application, usually externalized in a database or properties file, but updated very infrequently (days, weeks, months)? When the data is updated, it would be updated externally.

这通常是一个可以注入DAO的单例,因此能够管理自己的内容吗?我喜欢在这个服务上暴露一个refresh()方法,这将强制刷新(即通过MBean - 所以我不必反弹应用程序)的想法。

Would this normally be a singleton that I could inject with a DAO and would thus be able to manage its own contents? I like the idea of exposing a refresh() method on this service that would force a refresh (i.e., through an MBean - so I wouldn't have to bounce the application).

从另一个SO线程,听起来好像人们可能只是在必要时实例化DAO,并在该级别上透明缓存。

From the other SO thread, it sounds like people might just instantiate the DAO's whenever necessary and cache transparently at that level.

我有点像单例服务注入了从数据库加载数据的真实DAO,或者返回硬编码响应的模拟/测试双。然而,如果我通过java枚举来将这个服务实现为一个单例,这样可以通过Spring将其布线更有问题。

I kind of like the idea of the singleton service being injected with either a real DAO that loads data from the database, or else a mock/test-double that returns a hard-coded response. However, if I were to implement the service as a singleton via java enum's, this makes wiring it up via Spring a bit more problematic.

那么其他人通常如何处理参考资料?查询是否会在封面下进行缓存?或者单独的内存服务?

So, how do other people typically deal with reference data? Query-at-will but with caching under the covers? Or a separate in-memory service?

推荐答案

我通常使用Spring将DAO实现注入我的服务层,正如你所提除了我的基于SQL的实现之外,还经常有一个测试实现( XMLDao FlatFileDao )。对于小数据集,我通常会写入我自己的缓存,并从内存中的底层表中加载所有数据。

I typically inject a DAO implementation into my service layer using Spring and, as you mention often have a test implementation (XMLDao, FlatFileDao) in addition to my SQL-based implementation. For small datasets I usually write my own cache and store all data loaded from the underlying table(s) in memory.

我拥有合理的小数据集的优势。如果我正在处理较大的数据集,我可能会考虑现成的缓存解决方案,可能分布在多个JVM(如 Terracotta )。

Saying all that, I have the advantage of working with reasonably small datasets. If I were dealing with a larger dataset I may consider off-the-shelf caching solutions, possibly distributed across multiple JVMs (like Terracotta).

正如我在上一个线程中提到的,我还暴露了一个refresh()方法。在数据更新不需要及时传播的情况下,我只需通过MBean手动调用它。在我希望自动化的情况下,我使用Tibrv来监听数据库中的更新,并刷新缓存的数据(使用MS-SQL触发器生成Tibrv消息)。

As I mentioned in the previous thread I also expose a refresh() method. In cases where updates to the data do not need to propagate in a timely manner I simply call this manually via an MBean. In situations where I wish to automate this I've used Tibrv to listen to updates from the database and refresh the cached data (using an MS-SQL trigger to generate a Tibrv message).

我不太明白你对使用Java枚举来实现服务的参考 - 这将如何工作?

I don't quite understand your reference to using Java enums to implement the service - How would this work?

这篇关于参考数据模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆