![JAR search and dependency download from the Maven repository](/logo.png)
com.yomahub.akali.strategy.MethodHotspotStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of akali Show documentation
Show all versions of akali Show documentation
Local fallback and hotspot solutions in high traffic scenarios
The newest version!
package com.yomahub.akali.strategy;
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestUtil;
import com.alibaba.csp.sentinel.util.MethodUtil;
import com.alibaba.fastjson.JSON;
import com.yomahub.akali.enums.AkaliStrategyEnum;
import java.lang.reflect.Method;
public class MethodHotspotStrategy implements AkaliStrategy{
private TimedCache timedCache;
public MethodHotspotStrategy() {
timedCache = CacheUtil.newTimedCache(1000 * 60);
timedCache.schedulePrune(1000);
}
@Override
public AkaliStrategyEnum getStrategy() {
return AkaliStrategyEnum.HOT_METHOD;
}
@Override
public Object process(Object bean, Method method, Object[] args) throws Exception{
String hotKey = StrUtil.format("{}-{}", MethodUtil.resolveMethodName(method), DigestUtil.md5Hex(JSON.toJSONString(args)));
if (timedCache.containsKey(hotKey)){
return timedCache.get(hotKey);
}else{
Object result = method.invoke(bean, args);
timedCache.put(hotKey, result);
return result;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy