CacheManager

This commit is contained in:
redkale
2023-12-26 14:45:43 +08:00
parent fd3e33d836
commit 58bd2b08a4
5 changed files with 490 additions and 3 deletions

View File

@@ -5,9 +5,13 @@ package org.redkale.test.cache;
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.redkale.annotation.Resource;
import org.redkale.cache.CacheManager;
import org.redkale.cache.Cached;
import org.redkale.service.Service;
import org.redkale.source.Range;
@@ -19,6 +23,19 @@ import org.redkale.util.RedkaleException;
*/
public class CacheInstance implements Service {
@Resource
private CacheManager cacheManager;
//修改远程缓存的key值
public void updateName(String code, Map<String, Long> map) {
cacheManager.remoteSetString(code, code + "_" + map.get("id"), Duration.ofMillis(60));
}
@Cached(key = "#{code}_#{map.id}", remoteExpire = "60", timeUnit = TimeUnit.MILLISECONDS)
public String getName(String code, Map<String, Long> map) {
return code + "-" + map;
}
@Cached(key = "name", localExpire = "30")
public String getName() {
return "haha";
@@ -49,7 +66,7 @@ public class CacheInstance implements Service {
return CompletableFuture.completedFuture(new File("aa.txt"));
}
@Cached(key = "info_#{id}_file#{files.one}", localExpire = "30", remoteExpire = "60")
@Cached(key = "info_#{id}_file#{files.one}", localExpire = "30", remoteExpire = "60", timeUnit = TimeUnit.MILLISECONDS)
public CompletableFuture<Map<String, Integer>> getInfo2Async(ParamBean bean, int id, List<String> idList, Map<String, File> files) throws IOException, InstantiationException {
return CompletableFuture.completedFuture(null);
}