You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/06/27 12:43:05 UTC

[dubbo-website] branch master updated: [fix] 优化服务引用配置对象缓存 (#1153)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-website.git


The following commit(s) were added to refs/heads/master by this push:
     new 5303b063b0 [fix] 优化服务引用配置对象缓存 (#1153)
5303b063b0 is described below

commit 5303b063b00bc4befbbd87a8d9ba37fe9aeeb62e
Author: JIAN ZHONG <11...@qq.com>
AuthorDate: Mon Jun 27 20:43:01 2022 +0800

    [fix] 优化服务引用配置对象缓存 (#1153)
    
    * [fix] 优化服务引用配置对象缓存
    
    * [fix] 格式优化
---
 .../performance/reference-config-cache.md          | 62 ++++++++++------------
 1 file changed, 29 insertions(+), 33 deletions(-)

diff --git a/content/zh/docs3-building/java-sdk/advanced-features-and-usage/performance/reference-config-cache.md b/content/zh/docs3-building/java-sdk/advanced-features-and-usage/performance/reference-config-cache.md
index f5467cd3a9..16d03ba305 100644
--- a/content/zh/docs3-building/java-sdk/advanced-features-and-usage/performance/reference-config-cache.md
+++ b/content/zh/docs3-building/java-sdk/advanced-features-and-usage/performance/reference-config-cache.md
@@ -1,43 +1,39 @@
----
-type: docs
-title: "服务引用配置对象缓存"
-linkTitle: "服务引用配置对象缓存"
-weight: 2
-description: "在 Dubbo 中缓存 ReferenceConfig"
----
+
+---  
+type: docs  
+title: "服务引用配置对象缓存"  
+linkTitle: "服务引用配置对象缓存"  
+weight: 2  
+description: "在 Dubbo3 中缓存 ReferenceConfig"
+---   
+## 特性说明
 
 `ReferenceConfig` 实例很重,封装了与注册中心的连接以及与提供者的连接,需要缓存。否则重复生成 `ReferenceConfig` 可能造成性能问题并且会有内存和连接泄漏。在 API 方式编程时,容易忽略此问题。
 
 因此,自 `2.4.0` 版本开始, dubbo 提供了简单的工具类 `ReferenceConfigCache`用于缓存 `ReferenceConfig` 实例。
-
-使用方式如下:
-
-```java
-ReferenceConfig<XxxService> reference = new ReferenceConfig<XxxService>();
-reference.setInterface(XxxService.class);
-reference.setVersion("1.0.0");
-......
-ReferenceConfigCache cache = ReferenceConfigCache.getCache();
-// cache.get方法中会缓存 Reference对象,并且调用ReferenceConfig.get方法启动ReferenceConfig
-XxxService xxxService = cache.get(reference);
-// 注意! Cache会持有ReferenceConfig,不要在外部再调用ReferenceConfig的destroy方法,导致Cache内的ReferenceConfig失效!
-// 使用xxxService对象
-xxxService.sayHello();
-```
-
+## 使用场景
+## 使用方式
 消除 Cache 中的 `ReferenceConfig`,将销毁 `ReferenceConfig` 并释放对应的资源。
-
-```java
-ReferenceConfigCache cache = ReferenceConfigCache.getCache();
-cache.destroy(reference);
+```java  
+ReferenceConfig<XxxService> reference = new ReferenceConfig<XxxService>();  
+reference.setInterface(XxxService.class);  
+reference.setVersion("1.0.0");  
+......  
+ReferenceConfigCache cache = ReferenceConfigCache.getCache();  
+// cache.get方法中会缓存 Reference对象,并且调用ReferenceConfig.get方法启动ReferenceConfig  
+XxxService xxxService = cache.get(reference);  
+// 注意! Cache会持有ReferenceConfig,不要在外部再调用ReferenceConfig的destroy方法,导致Cache内的ReferenceConfig失效!  
+// 使用xxxService对象  
+xxxService.sayHello();  
 ```
-
+```java  
+ReferenceConfigCache cache = ReferenceConfigCache.getCache();  
+cache.destroy(reference);  
+```   
 缺省 `ReferenceConfigCache` 把相同服务 Group、接口、版本的 `ReferenceConfig` 认为是相同,缓存一份。即以服务 Group、接口、版本为缓存的 Key。
 
 可以修改这个策略,在 `ReferenceConfigCache.getCache` 时,传一个 `KeyGenerator`。详见 `ReferenceConfigCache` 类的方法。
-
-```java
-KeyGenerator keyGenerator = new ...
-ReferenceConfigCache cache = ReferenceConfigCache.getCache(keyGenerator );
+```java  
+KeyGenerator keyGenerator = new ...  
+ReferenceConfigCache cache = ReferenceConfigCache.getCache(keyGenerator);  
 ```
-