This commit is contained in:
ran.shang
2025-06-11 09:42:13 +08:00
commit 7e38b8d971
1935 changed files with 132836 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package com.newyetai.common.cache;
import java.util.Map;
import org.apache.commons.collections.MapUtils;
import com.google.common.collect.Maps;
/**
* @author sr on 2020-07-07
*/
public class DefaultCacheProvider implements ICacheProvider {
private Map<String, Long> numLimitMap = Maps.newConcurrentMap();
@Override
public boolean outLimit(final String key, Long maxNumLimit) {
Long currentNumLimit = null;
final Object lockKey = key.intern();
synchronized (lockKey) {
currentNumLimit = MapUtils.getLong(numLimitMap, key, 0L);
if (currentNumLimit >= maxNumLimit) {
return true;
}
currentNumLimit++;
numLimitMap.put(key, currentNumLimit);
}
return false;
}
}