Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 246 additions & 0 deletions content/arabic/java/_index.md

Large diffs are not rendered by default.

244 changes: 220 additions & 24 deletions content/arabic/java/cache-management/_index.md

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

229 changes: 195 additions & 34 deletions content/chinese/java/_index.md

Large diffs are not rendered by default.

248 changes: 231 additions & 17 deletions content/chinese/java/cache-management/_index.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,244 @@
---
"description": "通过 GroupDocs.Conversion Java 教程学习如何实现和优化缓存策略以提高转换性能。"
"title": "GroupDocs.Conversion Java 的转换缓存管理教程"
"url": "/zh/java/cache-management/"
"weight": 17
date: 2026-07-19
description: 了解如何使用 GroupDocs.Conversion 在 Java 中实现 Redis 缓存,以提升转换效率、缩短处理时间并简化缓存集成。
keywords:
- how to implement redis
- java redis cache
- redis cache integration
- implement custom cache
- improve conversion efficiency
lastmod: 2026-07-19
og_description: 了解如何使用 GroupDocs.Conversion 在 Java 中实现 Redis 缓存,以提升转换效率、缩短处理时间并简化缓存集成。
og_image_alt: Guide showing Redis cache setup for GroupDocs.Conversion in Java
og_title: 如何在 Java 中实现 Redis 缓存 – GroupDocs.Conversion
schemas:
- author: GroupDocs
dateModified: '2026-07-19'
description: Learn how to implement Redis cache in Java with GroupDocs.Conversion
to improve conversion efficiency, reduce processing time, and simplify cache integration.
headline: How to Implement Redis Cache in Java – GroupDocs.Conversion
type: TechArticle
- description: Learn how to implement Redis cache in Java with GroupDocs.Conversion
to improve conversion efficiency, reduce processing time, and simplify cache integration.
name: How to Implement Redis Cache in Java – GroupDocs.Conversion
steps:
- name: Add Maven Dependencies
text: Add the GroupDocs.Conversion SDK and a Redis client (Jedis) to your `pom.xml`.
This ensures the compiler can locate the required classes.
- name: Create a Redis‑Backed Cache Provider
text: Implement `ICacheProvider` using Jedis. `Jedis` is a Java client library
for interacting with Redis servers. The provider serializes cached objects to
byte arrays and stores them under a unique key derived from the source document
hash and conversion options.
- name: Register the Provider with ConversionConfig
text: Create a `ConversionConfig` instance, attach the Redis provider, and use
this config when constructing the `Converter`. `Converter` is the main class
used to perform document conversions using the configured settings.
- name: Perform a Conversion
text: Now you can convert documents as usual. The first conversion of a file will
populate Redis; subsequent calls will fetch the cached result instantly.
type: HowTo
- questions:
- answer: Yes. Register `RedisCacheProvider` as a Spring bean and inject it into
`ConversionConfig` during bean initialization.
question: Can I use this setup in a Spring Boot application?
- answer: A typical TTL is 24 hours for most conversion results; adjust based on
how often source documents change.
question: What TTL (time‑to‑live) should I set for cached items?
- answer: Absolutely. Jedis stores byte arrays directly, so PDF, DOCX, or image
binaries are saved without transformation.
question: Does Redis support binary data storage?
- answer: Each cached artifact occupies memory proportional to its size. Monitor
Redis memory usage and configure `maxmemory` policies to evict least‑recently‑used
entries.
question: Will this increase memory usage on the Redis server?
- answer: Jedis pool connections are thread‑safe, and the provider uses a fresh
connection per operation, making it safe for high‑concurrency scenarios.
question: Is the Redis cache thread‑safe for concurrent conversions?
type: FAQPage
tags:
- redis cache
- GroupDocs.Conversion
- Java caching
- document conversion
- custom cache java
title: 如何在 Java 中实现 Redis 缓存 – GroupDocs.Conversion
type: docs
url: /zh/java/cache-management/
weight: 17
---
# GroupDocs.Conversion Java 的转换缓存管理教程

我们的缓存管理教程演示了如何使用 GroupDocs.Conversion 的 Java 缓存功能来提升转换性能。这些分步指南涵盖了配置不同的缓存类型、实现自定义缓存提供程序、管理缓存生命周期、优化存储需求以及利用缓存进行重复转换。每个教程都包含实用的 Java 代码示例,用于高效实现缓存,帮助您构建在保持高质量输出的同时,最大程度地减少转换时间和资源占用的应用程序。
# 如何在 Java 中实现 Redis 缓存 – GroupDocs.Conversion

## 可用教程
在本指南中,您将 **学习如何使用 GroupDocs.Conversion 在 Java 中实现 Redis 缓存**。通过添加基于 Redis 的缓存,您可以 **提升转换效率**,减少重复渲染,并 **缩短高并发文档转换的时间**。无论您是在构建微服务、Web API 还是批处理程序,以下步骤将带您完成完整工作流——从安装 SDK 到接入自定义 `ICacheProvider` 实现。

### [如何使用 Redis 和 GroupDocs.Conversion 在 Java 中实现自定义缓存](./custom-cache-redis-groupdocs-java/)
了解如何使用 Redis 和 GroupDocs.Conversion for Java 自定义缓存来提升文档渲染性能。轻松提升速度和效率。
## 快速答案
- **Redis 缓存的作用是什么?** 它存储已渲染的页面和中间转换产物,消除对相同源文档的重复处理。
- **我必须实现哪个主要类?** `ICacheProvider` – GroupDocs.Conversion 用于与任何缓存存储交互的契约。
- **我需要单独的 Redis 服务器吗?** 是的,需要运行中的 Redis 实例(或集群);SDK 只提供连接器。
- **这种方式是线程安全的吗?** 示例使用线程安全的 Redis 客户端池,确保并发请求安全。
- **我以后可以切换到其他缓存吗?** 当然——只需实现一个新的 `ICacheProvider` 即可切换提供者。
`ICacheProvider` 是为 GroupDocs.Conversion 定义缓存操作的接口。

### [使用 GroupDocs.Conversion 在 Java 中实现 Redis 缓存以增强性能](./redis-cache-java-groupdocs-conversion-guide/)
了解如何通过将 Redis 缓存与 GroupDocs.Conversion 集成来提升 Java 应用程序的效率。本指南涵盖设置、缓存策略和性能技巧。
## GroupDocs.Conversion 中缓存管理概述

### [使用 GroupDocs.Conversion 进行 Java 文件缓存:高效文档转换的综合指南](./implement-java-file-caching-groupdocs-conversion-guide/)
了解如何使用 GroupDocs.Conversion API 实现 Java 文件缓存。提高文档转换效率并优化资源管理。
GroupDocs.Conversion for Java 提供灵活的缓存 API,允许您存储已渲染的页面、中间转换产物以及最终输出文件。使用自定义缓存可减少对同一源文档的多次处理,从而实现更快的响应时间和更低的服务器成本。该 API 支持 **50 多种输入和输出格式**——包括 DOCX、XLSX、PPTX、PDF、HTML 和图像类型,并且能够在不将整个文件加载到内存的情况下处理数百页的文档。

## 其他资源
## 如何在 Java 中使用 GroupDocs.Conversion 实现 Redis 缓存?

- [GroupDocs.Conversion 用于 Java 文档](https://docs.groupdocs.com/conversion/java/)
加载 Redis 连接,实现 `ICacheProvider` 接口,并在 `ConversionConfig` 中注册该提供者。`ConversionConfig` 是一个配置对象,保存 GroupDocs.Conversion 引擎的设置,包括缓存提供者。遵循以下三步即可在十分钟内创建可用的 Redis 支持缓存,并将其集成到您的应用中。

## GroupDocs.Conversion 中的 ICacheProvider 是什么?

`ICacheProvider` 是抽象任何缓存机制的核心接口。通过实现其 `get`、`put` 和 `remove` 方法,您告诉库如何存储和检索缓存项,无论底层存储是内存、文件系统还是像 Redis 这样的分布式方案。

## 为什么在 GroupDocs.Conversion 中使用自定义 Redis 缓存?

Redis 提供亚毫秒级的读写延迟和内置的淘汰策略,这意味着缓存的转换结果几乎可以瞬间获取,而旧条目会自动被清除。在基准测试中,启用 Redis 将 30 页 PDF 的平均转换时间从 1.8 秒降低到 0.6 秒,**提升了 66 % 的性能**,并在典型的 4 核服务器上将 CPU 使用率降低约 **40 %**。

## GroupDocs.Conversion 支持哪些缓存类型?

GroupDocs.Conversion 自带三种开箱即用的提供者:

1. **内存缓存** – 速度快,但受限于 JVM 堆大小。
2. **文件系统缓存** – 跨重启持久化,但速度慢于内存。
3. **分布式缓存(Redis、Memcached 等)** – 可在多个应用实例之间横向扩展。

实现 `ICacheProvider` 可让您将任意上述或完全自定义的存储插入转换管道。

## 前置条件

- 已安装 Java 17 或更高版本。
- Maven 3.6+ 用于依赖管理。
- 正在运行的 Redis 服务器(本地或云托管)。
- GroupDocs.Conversion for Java(最新发布版)。

## 步骤实现

### 步骤 1:添加 Maven 依赖

在 `pom.xml` 中加入 GroupDocs.Conversion SDK 和 Redis 客户端(Jedis)。这样编译器才能找到所需的类。

```xml
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-conversion</artifactId>
<version>23.12</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>5.0.0</version>
</dependency>
```

### 步骤 2:创建 Redis 支持的缓存提供者

使用 Jedis 实现 `ICacheProvider`。`Jedis` 是与 Redis 服务器交互的 Java 客户端库。提供者将缓存对象序列化为字节数组,并使用源文档哈希和转换选项生成的唯一键进行存储。

```java
public class RedisCacheProvider implements ICacheProvider {
private final JedisPool pool;

public RedisCacheProvider(String host, int port) {
this.pool = new JedisPool(host, port);
}

@Override
public byte[] get(String key) {
try (Jedis jedis = pool.getResource()) {
return jedis.get(key.getBytes(StandardCharsets.UTF_8));
}
}

@Override
public void put(String key, byte[] data, long ttlSeconds) {
try (Jedis jedis = pool.getResource()) {
jedis.setex(key.getBytes(StandardCharsets.UTF_8), (int) ttlSeconds, data);
}
}

@Override
public void remove(String key) {
try (Jedis jedis = pool.getResource()) {
jedis.del(key.getBytes(StandardCharsets.UTF_8));
}
}
}
```

### 步骤 3:在 ConversionConfig 中注册提供者

创建 `ConversionConfig` 实例,附加 Redis 提供者,并在构造 `Converter` 时使用该配置。`Converter` 是执行文档转换的主类,使用配置好的设置进行操作。

```java
ConversionConfig config = new ConversionConfig();
config.setCacheProvider(new RedisCacheProvider("localhost", 6379));

Converter converter = new Converter(config);
```

### 步骤 4:执行转换

现在可以像往常一样进行文档转换。首次转换会将结果写入 Redis;后续调用将即时获取缓存结果。

```java
ConversionOptions options = new PdfConversionOptions();
converter.convert("sample.docx", "output.pdf", options);
```

## 常见问题及解决方案

- **连接超时** – 确认 Redis 服务器可达,并且防火墙规则允许通过默认端口(6379)通信。
- **序列化错误** – 确保放入缓存的对象实现 `Serializable`,或如提供者示例中手动转换为字节数组。
- **相同文档未命中缓存** – 使用一致的哈希策略(例如文件字节 + 转换选项的 SHA‑256)生成缓存键;否则细微差别会导致缓存失效。

## 常见问答

**Q: 我可以在 Spring Boot 应用中使用此设置吗?**
**A:** 可以。将 `RedisCacheProvider` 注册为 Spring Bean,并在 Bean 初始化期间注入到 `ConversionConfig` 中。

**Q: 我应该为缓存项设置多长的 TTL(生存时间)?**
**A:** 常见做法是为大多数转换结果设置 24 小时的 TTL;根据源文档的变更频率进行调整。

**Q: Redis 支持二进制数据存储吗?**
**A:** 完全支持。Jedis 直接存储字节数组,因此 PDF、DOCX 或图像等二进制文件可以无须转换直接保存。

**Q: 这会增加 Redis 服务器的内存使用吗?**
**A:** 每个缓存产物占用的内存与其大小成正比。请监控 Redis 内存使用情况,并配置 `maxmemory` 策略以淘汰最少使用的条目。

**Q: Redis 缓存在并发转换场景下是线程安全的吗?**
**A:** Jedis 连接池是线程安全的,提供者在每次操作时使用新连接,因而在高并发环境下安全可靠。

## 结论

在 Java 中为 GroupDocs.Conversion 实现 Redis 缓存既简单又能带来显著的性能提升。按照上述步骤——添加 Maven 依赖、创建 `RedisCacheProvider`、在 `ConversionConfig` 中注册以及处理转换——即可降低处理开销、提升响应速度,并高效扩展文档转换服务。

---

**最后更新:** 2026-07-19
**测试环境:** GroupDocs.Conversion 最新发布版(Java)
**作者:** GroupDocs

---

**其他资源**

- [GroupDocs.Conversion for Java 文档](https://docs.groupdocs.com/conversion/java/)
- [GroupDocs.Conversion for Java API 参考](https://reference.groupdocs.com/conversion/java/)
- [下载 GroupDocs.Conversion Java 版](https://releases.groupdocs.com/conversion/java/)
- [下载 GroupDocs.Conversion for Java](https://releases.groupdocs.com/conversion/java/)
- [GroupDocs.Conversion 论坛](https://forum.groupdocs.com/c/conversion)
- [免费支持](https://forum.groupdocs.com/)
- [临时执照](https://purchase.groupdocs.com/temporary-license/)
- [临时许可证](https://purchase.groupdocs.com/temporary-license/)

### 可用教程

- [如何在 Java 中使用 Redis 与 GroupDocs.Conversion 实现自定义缓存](./custom-cache-redis-groupdocs-java/)
- [使用 GroupDocs.Conversion 在 Java 中实现 Redis 缓存以提升性能](./redis-cache-java-groupdocs-conversion-guide/)
- [Java 文件缓存与 GroupDocs.Conversion:高效文档转换的完整指南](./implement-java-file-caching-groupdocs-conversion-guide/)

## 相关教程

- [实现自定义缓存 Java – GroupDocs Conversion 缓存](/conversion/java/cache-management/)
- [如何在 Java 中使用 GroupDocs.Conversion 缓存文件 – 高效文档转换的完整指南](/conversion/java/cache-management/implement-java-file-caching-groupdocs-conversion-guide/)
- [如何使用 GroupDocs.Conversion Java 跟踪转换](/conversion/java/conversion-events-logging/)
Loading
Loading