This commit is contained in:
redkale
2024-05-30 20:35:40 +08:00
parent 30236f9bbc
commit 8cab0c78df
5 changed files with 509 additions and 511 deletions

View File

@@ -1,60 +1,60 @@
/*
*/
package org.redkale.cache.spi;
import java.util.Objects;
import org.redkale.util.MultiHashKey;
/**
* 缓存key生成器
*
* @see org.redkale.cache.Cached#key()
*
* <p>详情见: https://redkale.org
*
* @author zhangjx
* @since 2.8.0
*/
public interface CacheKeyGenerator {
/**
* 根据service和方法名生成key
*
* @param target Service对象
* @param action CacheAction对象
* @param params 参数值
* @return key值
*/
public String generate(Object target, CacheAction action, Object... params);
/**
* 生成器的名字
*
* @see org.redkale.cache.Cached#key()
*
* @return name
*/
public String name();
/**
* 根据MultiHashKey生成一个CacheKeyGenerator
* @param key MultiHashKey 不能为空
* @return CacheKeyGenerator
*/
public static CacheKeyGenerator create(MultiHashKey key) {
Objects.requireNonNull(key);
return new CacheKeyGenerator() {
@Override
public String generate(Object target, CacheAction action, Object... params) {
return key.keyFor(params);
}
@Override
public String name() {
return "";
}
};
}
}
/*
*/
package org.redkale.cache.spi;
import java.util.Objects;
import org.redkale.util.MultiHashKey;
/**
* 缓存key生成器
*
* @see org.redkale.cache.Cached#key()
*
* <p>详情见: https://redkale.org
*
* @author zhangjx
* @since 2.8.0
*/
public interface CacheKeyGenerator {
/**
* 根据service和方法名生成key
*
* @param target Service对象
* @param action CacheAction对象
* @param params 参数值
* @return key值
*/
public String generate(Object target, CacheAction action, Object... params);
/**
* 生成器的名字
*
* @see org.redkale.cache.Cached#key()
*
* @return name
*/
public String name();
/**
* 根据MultiHashKey生成一个CacheKeyGenerator
* @param key MultiHashKey 不能为空
* @return CacheKeyGenerator
*/
public static CacheKeyGenerator create(MultiHashKey key) {
Objects.requireNonNull(key);
return new CacheKeyGenerator() {
@Override
public String generate(Object target, CacheAction action, Object... params) {
return key.keyFor(params);
}
@Override
public String name() {
return "";
}
};
}
}