18339543638 пре 2 година
родитељ
комит
11ff48f2bb

+ 16 - 3
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/storage/provider/SysStorageApiProvider.java

@@ -4,6 +4,10 @@ import cn.tr.module.api.sys.storage.StoragePojo;
 import cn.tr.module.api.sys.storage.SysStorageApi;
 import cn.tr.module.sys.storage.service.IStorageFileService;
 import lombok.AllArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Component;
 
 import java.util.Collection;
@@ -17,10 +21,12 @@ import java.util.Map;
  * @Date: 2023年05月18日
  */
 @Component
-@AllArgsConstructor
 public class SysStorageApiProvider implements SysStorageApi {
-    private final IStorageFileService storageFileService;
-
+    @Autowired
+    private IStorageFileService storageFileService;
+    @Autowired
+    @Lazy
+    private SysStorageApiProvider sysStorageApiProvider;
     @Override
     public String upload(byte[] content, String filename, Long millis) throws Exception {
         return  storageFileService.upload(null,null,filename,content,millis).getId();
@@ -29,9 +35,11 @@ public class SysStorageApiProvider implements SysStorageApi {
     @Override
     public void removeById(String fileId) {
         storageFileService.remove(Collections.singleton(fileId));
+        sysStorageApiProvider.delCache(fileId);
     }
 
     @Override
+    @Cacheable(key = "#recordId",value = "global:storage")
     public byte[] obtainContent(String recordId) throws Exception {
         return storageFileService.obtainContent(recordId);
     }
@@ -40,4 +48,9 @@ public class SysStorageApiProvider implements SysStorageApi {
     public Map<String, StoragePojo> findStorage(Collection<String> storageIds) {
         return storageFileService.findStorageByIds(storageIds);
     }
+
+    @CacheEvict(key = "#recordId",value = "global:storage")
+    public void delCache(String recordId){
+
+    }
 }