简体   繁体   English

如何在 WSO2 ESB 6.6.0 中使代理内的缓存无效

[英]How to invalidate cache inside a proxy in WSO2 ESB 6.6.0

I would like to know how can I invalidate the cache created by the Cache Mediator just by calling a proxy.我想知道如何仅通过调用代理来使缓存调解器创建的缓存无效。
According to the doc we can do that by using a JMX Monitoring tool.根据文档,我们可以通过使用 JMX 监控工具来做到这一点。 But we do not want to do something like this.但是我们不想做这样的事情。

So I've made a custom mediator所以我做了一个自定义中介

import javax.cache.CacheException;
import javax.cache.Caching;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;

public class CacheInvalidateMediator extends AbstractMediator
{
    private static final Log log = LogFactory.getLog(CacheInvalidateMediator.class);

    public boolean mediate(MessageContext synCtx)
    {
        try
        {
            Caching.getCacheManager("cacheManager").getCache("mediatorCache").removeAll();
            log.info("Total mediator cache has been invalidated.");
        }
        catch(CacheException cacheException)
        {
            throw new CacheException("Error occurred while invalidating mediator cache. " + cacheException);
        }
        return true;
    }
}

It works for EI 6.2.0 but now for EI 6.6.0 it is deprecated and I can't figure how to do the same thing now.它适用于 EI 6.2.0,但现在适用于 EI 6.6.0,它已被弃用,我现在不知道如何做同样的事情。 Do you have any idea?你有什么主意吗?

Regards.问候。

EDIT编辑

I tried to do an iteration on getCaches().我试图对 getCaches() 进行迭代。 It seems that I do not have the right name for the cache manager.似乎我没有正确的缓存管理器名称。

public class CacheInvalidateMediator extends AbstractMediator { 
    private static final Log log = LogFactory.getLog(CacheInvalidateMediator.class);


    public boolean mediate(MessageContext context) { 
        try {
            log.info("JAVA REMOVING CACHE...");
            log.info(Caching.getCacheManager("cacheManager"));
            log.info(Caching.getCacheManager("cache"));
            Iterable<Cache<?, ?>> iterable1 = Caching.getCacheManagerFactory().getCacheManager("__default__").getCaches();
            log.info("iterate :");
            for(Cache<?, ?> cache : iterable1) {
                log.info("cache : "+cache.getName());
                cache.removeAll();
            }



            Iterable<Cache<?, ?>> iterable2 = Caching.getCacheManagerFactory().getCacheManager("cache").getCaches();
            log.info("iterate :");
            for(Cache<?, ?> cache : iterable2) {
                log.info("cache : "+cache.getName());
                cache.removeAll();
            }

            log.info("Total mediator cache has been invalidated.");

            log.info("JAVA CACHE INVALIDATE");
        } catch (Exception e) {
            log.info(e.toString());
        }
        return true;
    }
}

Based on github project , I've tried to use some constants, but anything seems to work.基于github 项目,我尝试使用一些常量,但似乎一切正常。

The caching implementation was totally rewritten in the later releases.缓存实现在以后的版本中被完全重写。 Hence using javax CacheManager to clear the cache would not work in EI 6.6.0.因此使用 javax CacheManager 清除缓存在 EI 6.6.0 中不起作用。 But still there is a MBean implementation to invalidate the cache.但是仍然有一个 MBean 实现使缓存无效。 https://github.com/wso2/carbon-mediation/blob/master/components/mediators/cache/org.wso2.carbon.mediator.cache/src/main/java/org/wso2/carbon/mediator/cache/MediatorCacheInvalidator.java https://github.com/wso2/carbon-mediation/blob/master/components/mediators/cache/org.wso2.carbon.mediator.cache/src/main/java/org/wso2/carbon/mediator/cache/ MediatorCacheInvalidator.java

You should try out an implementation to invoke this MBean to invalidate the cache.您应该尝试一个实现来调用此 MBean 以使缓存无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM