public interface CacheService {
@Nullable
<T> T get(String cacheName, @NonNull String key, @NonNull Class<T> clazz);
/** @deprecated */
@Nullable
@Deprecated
<T> T get(String cacheName, @NonNull String key, @NonNull BiFunction<String, String, T> loadHandle, @NonNull Class<T> clazz);
Stream<String> getKeysByPattern(String cacheName, @NonNull String pattern);
<T> void set(String cacheName, @NonNull String key, @NonNull T value);
<T> void set(String cacheName, @NonNull String key, @NonNull T value, long timeToLive, @NonNull TimeUnit timeUnit);
boolean deleteKey(String cacheName, @NonNull String key);
long deleteKeyByPrefix(String cacheName, @NonNull String prefix) throws UnsupportedOperationException;
boolean expireKey(String cacheName, @NonNull String key, long timeToLive, @NonNull TimeUnit timeUnit);
<T> boolean replace(String cacheName, @NonNull String key, @NonNull T oldValue, @NonNull T newValue);
boolean cas(String cacheName, @NonNull String key, @NonNull Version value);
long getRemainTimeToLive(String cacheName, @NonNull String key);
IAtomicLong getAtomicLong(String cacheName, @NonNull String key);
<T> Map<String, T> getHash(String cacheName, @NonNull String key, @NonNull Class<T> clazz);
@Nullable
<T> T getHashValue(String cacheName, @NonNull String key, @NonNull String hashKey, @NonNull Class<T> clazz);
<T> T putHashValue(String cacheName, @NonNull String key, @NonNull String hashKey, @NonNull T value);
@Nullable
<T> T deleteHashValue(String cacheName, @NonNull String key, @NonNull String hashKey);
/** @deprecated */
@Deprecated
<T> Map<String, T> getTimedHash(String cacheName, @NonNull String key, @NonNull Class<T> clazz);
/** @deprecated */
@Deprecated
@Nullable
<T> T getTimedHashValue(String cacheName, @NonNull String key, @NonNull String hashKey, @NonNull Class<T> clazz);
/** @deprecated */
@Deprecated
<T> T putTimedHashValue(String cacheName, @NonNull String key, @NonNull String hashKey, @NonNull T value);
/** @deprecated */
@Deprecated
<T> T putTimedHashValue(String cacheName, @NonNull String key, @NonNull String hashKey, @NonNull T value, long timeToLive, @NonNull TimeUnit timeUnit);
/** @deprecated */
@Deprecated
@Nullable
<T> T deleteTimedHashValue(String cacheName, @NonNull String key, @NonNull String hashKey);
<T> boolean addSortedSetValue(String cacheName, @NonNull String key, @NonNull T value, double score);
<T> int addSortedSetValueReturnSize(String cacheName, @NonNull String key, @NonNull T value, double score);
<T> Collection<T> rangeSortedByScore(String cacheName, @NonNull String key, double min, double max, @NonNull Class<T> clazz);
<T> boolean removeSortedSetValue(String cacheName, @NonNull String key, @NonNull T value);
<T> Collection<T> pollSortedByScore(String cacheName, @NonNull String key, double min, double max, @NonNull Class<T> clazz);
<T> Collection<T> pollSortedByScore(String cacheName, @NonNull String key, double min, double max, int count, @NonNull Class<T> clazz);
<T> Collection<T> pollFirst(String cacheName, @NonNull String key, int count, @NonNull Class<T> clazz);
<T> Collection<T> pollFirst(String cacheName, @NonNull String key, int count, double min, double max, @NonNull Class<T> clazz);
@Nullable
<T> T peekFirst(String cacheName, @NonNull String key, @NonNull Class<T> clazz);
int getSortedSetSize(String cacheName, @NonNull String key);
<T> Set<T> getSet(String cacheName, @NonNull String key, @NonNull Class<T> clazz);
<T> List<T> getList(String cacheName, @NonNull String key, @NonNull Class<T> clazz);
<T> Queue<T> getQueue(String cacheName, @NonNull String key, @NonNull Class<T> clazz);
<T> Deque<T> getDeque(String cacheName, @NonNull String key, @NonNull Class<T> clazz);
<T> BlockingQueue<T> getBlockingQueue(String cacheName, @NonNull String key, @NonNull Class<T> clazz);
<T> BlockingDeque<T> getBlockingDeque(String cacheName, @NonNull String key, @NonNull Class<T> clazz);
}
这是项目里面的缓存接口,我实现的部分(get)有点问题,如下,怎么修改:
@Slf4j
@Service
public class WebSocketResultCacheService {
public static final String WEBSOCKET_RESULT = "websocket:result";
private static final int FILE_ID_TIME_OUT = 30;
private static final TimeUnit FILE_ID_TIME_OUT_UNIT = TimeUnit.MINUTES;
@Autowired
private CacheService cacheService;
@Autowired
private ObjectMapper objectMapper; // Jackson ObjectMapper
/**
* @param vmsId vmsId
* @param taskId taskId
* @return
*/
public <T> getResult(String vmsId, String taskId) {
String cacheKey = buildCacheKey(vmsId, taskId);
return cacheService.get(WEBSOCKET_RESULT, cacheKey, );
}
/**
* @param vmsId vmsId
* @param taskId taskId
* @param dto WebSocketResultDTO
*/
public <T> void setValue(String vmsId, String taskId, WebSocketResultDTO<T> dto) {
String cacheKey = buildCacheKey(vmsId, taskId);
// todo 修改缓存名字 RedisKey.WEBSOCKET_RESULT
cacheService.set(WEBSOCKET_RESULT, cacheKey, dto, FILE_ID_TIME_OUT, FILE_ID_TIME_OUT_UNIT);
}
/**
* @param vmsId vmsId
* @param taskId taskId
*/
public void delete(String vmsId, String taskId) {
String cacheKey = buildCacheKey(vmsId, taskId);
// todo 修改缓存名字 RedisKey.WEBSOCKET_RESULT
cacheService.deleteKey(WEBSOCKET_RESULT, cacheKey);
}
private String buildCacheKey(String vmsId, String taskId) {
return String.format("websocket:result:%s:%s", vmsId, taskId);
}
}
最新发布