原标题:使用 Pivotal GemFire 缓存数据(Spring中国教育管理中心)
本指南演练了使用阿帕奇大地的数据管理系统,用于缓存应用程序代码中的某些调用。
有关Apache Geode概念和从Apache Geode访问数据的更多一般知识,请阅读指南,使用 Apache Geode 访问数据.
您将构建的内容
您将构建一个服务,该服务从CloudFoundry托管的报价服务请求报价,并将其缓存在Apache Geode中。
然后,您将看到再次获取相同的报价消除了对报价服务的昂贵调用,因为Spring的缓存抽象由Apache Geode支持,将用于缓存结果,给定相同的请求。
报价服务位于...
https://quoters.apps.pcfone.io
报价服务具有以下 API...
GET /api - get all quotes
GET /api/random - get random quote
GET /api/{id} - get specific quote
您将需要什么
- 约15分钟
- 喜欢的文本编辑器或 IDE
- JDK 1.8或更高版本
- 格拉德尔 4+或梅文 3.2+
- 您还可以将代码直接导入到 IDE 中:
- 弹簧工具套件 (STS)
- IntelliJ IDEA
如何完成本指南
像大多数春天一样入门指南,您可以从头开始并完成每个步骤,也可以绕过您已经熟悉的基本设置步骤。无论哪种方式,你最终都会得到工作代码。
要从头开始,请转到从 Spring Initializr 开始.
要跳过基础知识,请执行以下操作:
- 下载并解压缩本指南的源存储库,或使用Git:git clone https://github.com/spring-guides/gs-caching-gemfire.git
- 光盘成gs-caching-gemfire/initial
- 跳到创建用于提取数据的可绑定对象.
完成后,您可以根据 中的代码检查结果。
gs-caching-gemfire/complete
从 Spring Initializr 开始
对于所有Spring应用程序,您应该从Spring Initializr.Spring Initializr提供了一种快速的方法来提取应用程序所需的所有依赖项,并为您完成许多设置。此示例需要"Apache Geode 的 Spring for Apache Geode"依赖项。
以下清单显示了使用 Maven 时的示例文件:pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
</parent>
<groupId>org.springframework</groupId>
<artifactId>gs-caching-gemfire</artifactId>
<version>0.1.0</version>
<properties>
<spring-shell.version>1.2.0.RELEASE</spring-shell.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<g