0

我使用 spring data JPA 和 data-source 作为 spring bean 编写了 CacheLoader 和 CacheWriter 来连接到数据库并获取数据......现在我需要在服务器缓存中插入这些 loader 和 writer......我怎样才能有效地做到这一点。

我想我需要在 cache.xml 中使用以下元素并从 gfsh 命令 shell 引用这个 xml 文件:

<initializer>
    <class-name>org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer</class-name>
    <parameter name="contextConfigLocations">
    <string>application-context.xml</string>
    </parameter>
</initializer>

在这种情况下,我有以下问题:

1. 建议将上述从 gemfire 引导 Spring 应用程序上下文的方法用于生产?

2.实现这一目标的其他选择是什么?

3.我已经完成了在我的客户端中创建客户端缓存的工作,并插入了这些缓存加载器和缓存写入器,并且由于我的客户端是 Spring 应用程序,它们正在执行,但是这种方法是否建议用于生产?

4

1 回答 1

0

关于1...

这种方法绝对有效,并且使需要主要使用 Spring Data GemFire 的 XML 命名空间配置的 GemFire 服务器的用户/管理员能够使用 Gfsh 启动。目前,Gfsh 不接受用于引导 GemFire 服务器的 Spring XML 上下文配置文件。因此,为了使用 GemFire 作为需要使用 Gfsh 启动的对等缓存来部署 Spring 应用程序,您需要最少的 cache.xml 片段,因此采用了这种方法。

关于2..

没有使用 Gfsh。当然,如果您不必在生产环境中使用 Gfsh 来启动 GemFire 服务器,那么一个简单的 Java 类具有一个主要方法来引导一个 Spring 应用程序上下文,该上下文还配置一个 GemFire 对等节点或客户端缓存就足够了......

public class GemFireServer {
  public static void main(String[] args) {
    ConfigurableApplicationContext applicationContext = new ClassPathApplicationContext("/path/to/spring/data/gemfire/application/context/config.xml");
    applicationContext.registerShutdownHook();
  }
}

但是,我要指出的是,在 GemFire 8.0 中,计划在 7 月下旬发布使用 Spring 配置启动和引导 GemFire 服务器的功能。即你将能够...

gfsh>start server --name=MyServer --log-level=config --spring-xml-location=/path/to/spring/config.xml

关于3...

通常,在服务器上使用 CacheLoaders 和 CacheWriters 来加载和填充缓存未命中的值以及“直写”到后端的外部持久存储。虽然,您可以在客户端上指定 CacheLoaders 和 CacheWriters,但这是非典型的,并且仅在 GemFire 集群无法访问数据源时才需要,可能是因为数据源特定于客户端。

于 2014-07-06T17:58:09.383 回答