Skip to content

Commit

Permalink
add deprecated and translate comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Roiocam committed Aug 22, 2024
1 parent fb1e4c7 commit 687a0f6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author huangli
*/
public class MultiLevelCache<K, V> extends AbstractCache<K, V> {

private Cache[] caches;

private MultiLevelCacheConfig<K, V> config;
Expand Down Expand Up @@ -102,11 +103,11 @@ private void checkResultAndFillUpperCache(K key, int i, CacheValueHolder<V> h) {
long now = System.currentTimeMillis();
if (now <= currentExpire) {
/*
原来这里有两种情况:
- 如果 isUseExpireOfSubCache,那么让 Local 自己选择过期时间
- 如果为 false,那么选择远程的剩余时间作为过期时间
现在的代码,总是选择远程的剩余时间作为过期时间,但是增加了参数 isForce 来控制不能超过配置的本地缓存时间
而对于用户直接 PUT_EXPIRED 则允许此类操作
There are two situations here from the legacy version:
- if isUseExpireOfSubCache, let subordinate cache choose the expiration time by itself
- if not, choose the remaining time of the current cache as the expiration time
In the current version, the remaining time of the current cache is always chosen as the expiration time,
but a parameter isForce is added to control that it cannot exceed the expiration time that subordinate cache configured
*/
long restTtl = currentExpire - now;
if (restTtl > 0) {
Expand Down Expand Up @@ -172,7 +173,7 @@ private CacheResult PUT_caches(int lastIndex, K key, V value, long expire, TimeU
if (timeUnit == null) {
r = cache.PUT(key, value);
} else {
// 只有 isForce = 用户强制 或者 expire <= 本地缓存时间 才会使用参数的 expire
// only use argument expiration time when user force and expiration minus than configuration
if (isForce || expire <= cache.config().getExpireAfterWriteInMillis()) {
r = cache.PUT(key, value, expire, timeUnit);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public void setCaches(List<Cache> caches) {
getConfig().setCaches(caches);
}

@Deprecated
public T useExpireOfSubCache(boolean useExpireOfSubCache) {
return self();
}

@Deprecated
public void setUseExpireOfSubCache(boolean useExpireOfSubCache) {
}

@Override
public T keyConvertor(Function<Object, Object> keyConvertor) {
throw new UnsupportedOperationException("MultiLevelCache do not need a key convertor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
public class MultiLevelCacheConfig<K, V> extends CacheConfig<K, V> {
private List<Cache<K, V>> caches = new ArrayList<>();
private boolean useExpireOfSubCache;

@Override
public MultiLevelCacheConfig clone() {
Expand All @@ -27,4 +28,14 @@ public List<Cache<K, V>> getCaches() {
public void setCaches(List<Cache<K, V>> caches) {
this.caches = caches;
}

@Deprecated
public boolean isUseExpireOfSubCache() {
return useExpireOfSubCache;
}

@Deprecated
public void setUseExpireOfSubCache(boolean useExpireOfSubCache) {
this.useExpireOfSubCache = useExpireOfSubCache;
}
}

0 comments on commit 687a0f6

Please sign in to comment.