You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/08/26 13:44:02 UTC

[GitHub] [dubbo] gang0713 opened a new issue #8610: 建议增加对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

gang0713 opened a new issue #8610:
URL: https://github.com/apache/dubbo/issues/8610


   希望的效果,当接口方法上有@Cached注解,先取缓存,缓存没有再调用远程方法。
   https://github.com/alibaba/jetcache/issues/562


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 commented on issue #8610: 建议增加对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 commented on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-907555402


   @24kpure  官方能否提供Cache的jetcache的支持。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 edited a comment on issue #8610: 建议增加对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 edited a comment on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-907594667


   @24kpure  最好是实现方法级别的缓存,https://github.com/qy8502/jetcache-plus/tree/master/jetcache-plus-dubbo
   
   3.1. 背景
   目前通过dubbo实现微服务,跨服务获取数据,往往先通过dubbo再到redis的方式获取数据。这样做在缓存可以命中的情况下多出了大约10ms的dubbo时间消耗和相应带宽消耗,比较浪费。需要调用者先写走redis再走dubbo。
   
   3.2. 实现方式
   利用 dubbo动态代理扩展 实现将服务消费者的代理实例,再包装一层代理实现缓存注解的拦截的处理。
   
   通过JetCacheDubboProxyFactoryWrapper实现ProxyFactory接口,根据是否是包含缓存的服务,不是直接返回dubbo代理,是创建三层缓存代理:
   
   第一层代理仅仅为了判断是否是@Cached注解方法,如果不是直接dubbo调用,@CacheInvalidate或@CacheUpdate都应当由远端服务处理完逻辑后处理缓存,不在此多管闲事。
   如果是@Cached注解方法,通过JetCacheInterceptor创建第二层的缓存代理类,调用时处理缓存。
   缓存未命中时,进入第三层代理,判断方法是否default方法体,如果是直接执行default逻辑,不是则执行dubbo调用。 这种设计提供了一种解决方案,服务声明两个方法getXxx和getXxxNoCache之类,前者注解@Cached且defaulte方法体调用后者,后者的实现处理具体业务逻辑。 这样使得dubbo消费者调用getXxx时,在消费者端执行缓存处理。 缓存如果未命中,在消费者端就转为dubbo调用getXxxNoCache方法。避免在服务提供端调用getXxx再执行一遍缓存处理逻辑。
   switcher proxy
   ┌──────────────────────────────────────────────────┐
   │  @Cached method         /       other            │
   │         │                         │              │
   │         │                         │              │
   │         ▼                         │              │
   │  cache interceptor proxy          │              │
   │  ┌────────────────────────────────┼───────────┐  │
   │  │  handle cache                  │           │  │
   │  │       │                        │           │  │
   │  │       │                        │           │  │
   │  │       ▼                        │           │  │
   │  │  default method proxy          │           │  │
   │  │  ┌─────────────────────────────┼────────┐  │  │
   │  │  │  is default method    /     │ other  │  │  │
   │  │  │      │                      │    │   │  │  │
   │  │  │      │                      │    │   │  │  │
   │  │  │      │                      ▼    ▼   │  │  │
   │  │  │      │             dubbo proxy       │  │  │
   │  │  │      │             ┌──────────────┐  │  │  │
   │  │  │      ▼             │  rpc         │  │  │  │
   │  │  │  default method ──►│              │  │  │  │
   │  │  │                    │              │  │  │  │
   │  │  │                    └──────────────┘  │  │  │
   │  │  │                                      │  │  │
   │  │  └──────────────────────────────────────┘  │  │
   │  │                                            │  │
   │  └────────────────────────────────────────────┘  │
   │                                                  │
   └──────────────────────────────────────────────────┘


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 commented on issue #8610: 建议增加支持方法级别的缓存,对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 commented on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-910016226


    @24kpure      如果官方能提供 @DubboCache基本方法的注解是最好了,为dubbo消费者方法直接使用缓存的能力,当缓存不存在时,再访问远程dubbo服务。参考实现:  https://github.com/bohrqiu/dubbo-cache


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 commented on issue #8610: 建议增加支持方法级别的缓存,对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 commented on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-910016226


    @24kpure      如果官方能提供 @DubboCache基本方法的注解是最好了,为dubbo消费者方法直接使用缓存的能力,当缓存不存在时,再访问远程dubbo服务。参考实现:  https://github.com/bohrqiu/dubbo-cache


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 edited a comment on issue #8610: 建议增加对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 edited a comment on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-907594667


   @24kpure  @ AlbumenJ  最好是实现方法级别的缓存,https://github.com/qy8502/jetcache-plus/tree/master/jetcache-plus-dubbo
   
   3.1. 背景
   目前通过dubbo实现微服务,跨服务获取数据,往往先通过dubbo再到redis的方式获取数据。这样做在缓存可以命中的情况下多出了大约10ms的dubbo时间消耗和相应带宽消耗,比较浪费。需要调用者先写走redis再走dubbo。
   
   3.2. 实现方式
   利用 dubbo动态代理扩展 实现将服务消费者的代理实例,再包装一层代理实现缓存注解的拦截的处理。
   
   通过JetCacheDubboProxyFactoryWrapper实现ProxyFactory接口,根据是否是包含缓存的服务,不是直接返回dubbo代理,是创建三层缓存代理:
   
   第一层代理仅仅为了判断是否是@Cached注解方法,如果不是直接dubbo调用,@CacheInvalidate或@CacheUpdate都应当由远端服务处理完逻辑后处理缓存,不在此多管闲事。
   如果是@Cached注解方法,通过JetCacheInterceptor创建第二层的缓存代理类,调用时处理缓存。
   缓存未命中时,进入第三层代理,判断方法是否default方法体,如果是直接执行default逻辑,不是则执行dubbo调用。 这种设计提供了一种解决方案,服务声明两个方法getXxx和getXxxNoCache之类,前者注解@Cached且defaulte方法体调用后者,后者的实现处理具体业务逻辑。 这样使得dubbo消费者调用getXxx时,在消费者端执行缓存处理。 缓存如果未命中,在消费者端就转为dubbo调用getXxxNoCache方法。避免在服务提供端调用getXxx再执行一遍缓存处理逻辑。
   switcher proxy
   ┌──────────────────────────────────────────────────┐
   │  @Cached method         /       other            │
   │         │                         │              │
   │         │                         │              │
   │         ▼                         │              │
   │  cache interceptor proxy          │              │
   │  ┌────────────────────────────────┼───────────┐  │
   │  │  handle cache                  │           │  │
   │  │       │                        │           │  │
   │  │       │                        │           │  │
   │  │       ▼                        │           │  │
   │  │  default method proxy          │           │  │
   │  │  ┌─────────────────────────────┼────────┐  │  │
   │  │  │  is default method    /     │ other  │  │  │
   │  │  │      │                      │    │   │  │  │
   │  │  │      │                      │    │   │  │  │
   │  │  │      │                      ▼    ▼   │  │  │
   │  │  │      │             dubbo proxy       │  │  │
   │  │  │      │             ┌──────────────┐  │  │  │
   │  │  │      ▼             │  rpc         │  │  │  │
   │  │  │  default method ──►│              │  │  │  │
   │  │  │                    │              │  │  │  │
   │  │  │                    └──────────────┘  │  │  │
   │  │  │                                      │  │  │
   │  │  └──────────────────────────────────────┘  │  │
   │  │                                            │  │
   │  └────────────────────────────────────────────┘  │
   │                                                  │
   └──────────────────────────────────────────────────┘


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] 24kpure commented on issue #8610: 建议增加对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
24kpure commented on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-907135339


   Thanks for your advice.In my views,it is unwise for dubbo to support a specific cache dependency. Dubbo just provides some base cache implement.If you want more, it's a  good way to add a implement  of **org.apache.dubbo.cache.CacheFactory** according to spi.
   ## You can also have a look at these class
   - org.apache.dubbo.cache.Cache
   - org.apache.dubbo.config.annotation.DubboReference#cache


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 commented on issue #8610: 建议增加对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 commented on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-907594667


   @24kpure  最好是实现方法级别的缓存,https://github.com/qy8502/jetcache-plus/tree/master/jetcache-plus-dubbo


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] 24kpure commented on issue #8610: 建议增加支持方法级别的缓存,对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
24kpure commented on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-908271177


   Dubbo supports method level cache,you can have a try. As for cache operation,it depends on your bussiness design.It's my personal opinion and good luck for you .
   
   ## reference class
   org.apache.dubbo.config.annotation.Method#cache


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 edited a comment on issue #8610: 建议增加对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 edited a comment on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-907594667






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 commented on issue #8610: 建议增加对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 commented on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-907556928


   @24kpure 目前是不是还不支持方法级别的缓存


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 edited a comment on issue #8610: 建议增加支持方法级别的缓存,对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 edited a comment on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-910016226


    @24kpure      如果官方能提供 @DubboCache基本方法的注解是最好了,为dubbo消费者方法直接使用缓存的能力,当缓存不存在时,再访问远程dubbo服务。参考实现:  https://github.com/bohrqiu/dubbo-cache
   相对于dubbo默认的缓存机制,此项目具有如下优点:
   原生dubbo cache机制只能缓存结果到消费者jvm中,并且cache key不能选择。
   缓存key生成灵活,和spring 声明式缓存一致,采用spring el表达式
   可以扩展CacheKeyValidator接口,实现键缓存策略
   可以扩展CacheValueValidator接口,实现值缓存策略
   由于采用分布式缓存,服务提供端可以灵活控制缓存


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 edited a comment on issue #8610: 建议增加支持方法级别的缓存,对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 edited a comment on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-910016226


    @24kpure    @AlbumenJ   如果官方能提供 @DubboCache基本方法的注解是最好了,为dubbo消费者方法直接使用缓存的能力,当缓存不存在时,再访问远程dubbo服务。参考实现:  https://github.com/bohrqiu/dubbo-cache
   相对于dubbo默认的缓存机制,此项目具有如下优点:
   原生dubbo cache机制只能缓存结果到消费者jvm中,并且cache key不能选择。
   缓存key生成灵活,和spring 声明式缓存一致,采用spring el表达式
   可以扩展CacheKeyValidator接口,实现键缓存策略
   可以扩展CacheValueValidator接口,实现值缓存策略
   由于采用分布式缓存,服务提供端可以灵活控制缓存


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] gang0713 edited a comment on issue #8610: 建议增加支持方法级别的缓存,对阿里jetcache缓存的支持,当把@Cached注解缓存定义在接口方法上时,不是先取缓存,还是通过RPC进行了远程调用。

Posted by GitBox <gi...@apache.org>.
gang0713 edited a comment on issue #8610:
URL: https://github.com/apache/dubbo/issues/8610#issuecomment-910016226






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org