格式化
This commit is contained in:
@@ -94,7 +94,7 @@ public interface CachedManager extends Resourcable {
|
||||
* 处理指定缓存key的{@link org.redkale.cached.spi.CachedAction}<br>
|
||||
* 可用于动态调整缓存时长
|
||||
*
|
||||
* @param templetKey 缓存key
|
||||
* @param templetKey 模板key
|
||||
* @param consumer 处理函数
|
||||
*/
|
||||
public void acceptCachedAction(String templetKey, Consumer<CachedAction> consumer);
|
||||
|
||||
@@ -85,7 +85,7 @@ public class CachedAction {
|
||||
this.paramNames = paramNames;
|
||||
this.methodName = method.getName();
|
||||
this.fieldName = Objects.requireNonNull(fieldName);
|
||||
this.templetKey = cached.getKey();
|
||||
this.templetKey = cached.getTempletKey();
|
||||
Type returnType = method.getGenericReturnType();
|
||||
this.async = CompletableFuture.class.isAssignableFrom(TypeToken.typeToClass(returnType));
|
||||
this.resultType = this.async ? ((ParameterizedType) returnType).getActualTypeArguments()[0] : returnType;
|
||||
@@ -93,7 +93,7 @@ public class CachedAction {
|
||||
|
||||
String init(ResourceFactory resourceFactory, Object service) {
|
||||
this.manager = resourceFactory.load(cached.getManager(), CachedManager.class);
|
||||
final String key = environment.getPropertyValue(cached.getKey());
|
||||
final String key = environment.getPropertyValue(cached.getTempletKey());
|
||||
if (key.startsWith("@")) { // 动态加载缓存key生成器
|
||||
String generatorName = key.substring(1);
|
||||
this.keyGenerator = resourceFactory.findChild(generatorName, CachedKeyGenerator.class);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class CachedEntry {
|
||||
|
||||
private String manager;
|
||||
|
||||
private String key;
|
||||
private String templetKey;
|
||||
|
||||
private String localExpire;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class CachedEntry {
|
||||
|
||||
public CachedEntry(DynForCached cached) {
|
||||
this.manager = cached.manager();
|
||||
this.key = cached.key();
|
||||
this.templetKey = cached.key();
|
||||
this.localExpire = cached.localExpire();
|
||||
this.remoteExpire = cached.remoteExpire();
|
||||
this.timeUnit = cached.timeUnit();
|
||||
@@ -43,7 +43,7 @@ public class CachedEntry {
|
||||
|
||||
public CachedEntry(Cached cached) {
|
||||
this.manager = cached.manager();
|
||||
this.key = cached.key();
|
||||
this.templetKey = cached.key();
|
||||
this.localExpire = cached.localExpire();
|
||||
this.remoteExpire = cached.remoteExpire();
|
||||
this.timeUnit = cached.timeUnit();
|
||||
@@ -54,8 +54,8 @@ public class CachedEntry {
|
||||
return manager;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
public String getTempletKey() {
|
||||
return templetKey;
|
||||
}
|
||||
|
||||
public String getLocalExpire() {
|
||||
|
||||
@@ -159,7 +159,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
||||
keys.clear();
|
||||
long now = System.currentTimeMillis();
|
||||
container.forEach((k, x) -> {
|
||||
if (x.expireMills > 0 && (now > (x.lastAccessed + x.expireMills))) {
|
||||
if (x.isExpired(now)) {
|
||||
keys.add(x.key);
|
||||
}
|
||||
});
|
||||
@@ -171,7 +171,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
||||
}
|
||||
long now2 = System.currentTimeMillis();
|
||||
rateLimitContainer.forEach((k, x) -> {
|
||||
if (x.expireMills > 0 && (now2 > (x.lastAccessed + x.expireMills))) {
|
||||
if (x.isExpired(now2)) {
|
||||
keys.add(x.key);
|
||||
}
|
||||
});
|
||||
@@ -2604,10 +2604,13 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
public boolean isExpired(long now) {
|
||||
return expireMills > 0 && (initTime + expireMills) < now;
|
||||
}
|
||||
|
||||
@ConvertColumn(ignore = true)
|
||||
public boolean isExpired() {
|
||||
long now = System.currentTimeMillis();
|
||||
return expireMills > 0 && (initTime + expireMills) < now;
|
||||
return isExpired(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void lock() {
|
||||
@@ -2700,15 +2703,18 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
||||
return JsonFactory.root().getConvert().convertTo(this);
|
||||
}
|
||||
|
||||
@ConvertColumn(ignore = true)
|
||||
public boolean isExpired() {
|
||||
long now = System.currentTimeMillis();
|
||||
public boolean isExpired(long now) {
|
||||
if (endTime > 0) {
|
||||
return now >= endTime;
|
||||
}
|
||||
return expireMills > 0 && (initTime + expireMills) < now;
|
||||
}
|
||||
|
||||
@ConvertColumn(ignore = true)
|
||||
public boolean isExpired() {
|
||||
return isExpired(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
// value类型只能是byte[]/String/AtomicLong
|
||||
public static <T> T serialToObj(@Nonnull Convert convert, @Nonnull Type type, Serializable value) {
|
||||
if (value == null) {
|
||||
|
||||
Reference in New Issue
Block a user