diff --git a/server/src/main/java/cn/keking/service/cache/impl/CacheServiceJDKImpl.java b/server/src/main/java/cn/keking/service/cache/impl/CacheServiceJDKImpl.java index 04ffefe9..f3430cae 100644 --- a/server/src/main/java/cn/keking/service/cache/impl/CacheServiceJDKImpl.java +++ b/server/src/main/java/cn/keking/service/cache/impl/CacheServiceJDKImpl.java @@ -101,6 +101,7 @@ public class CacheServiceJDKImpl implements CacheService { initPDFCachePool(CacheService.DEFAULT_PDF_CAPACITY); initIMGCachePool(CacheService.DEFAULT_IMG_CAPACITY); initPdfImagesCachePool(CacheService.DEFAULT_PDFIMG_CAPACITY); + initMediaConvertCachePool(CacheService.DEFAULT_MEDIACONVERT_CAPACITY); } @Override diff --git a/server/src/main/java/cn/keking/service/cache/impl/CacheServiceRedisImpl.java b/server/src/main/java/cn/keking/service/cache/impl/CacheServiceRedisImpl.java index 0472a257..b7cb971a 100644 --- a/server/src/main/java/cn/keking/service/cache/impl/CacheServiceRedisImpl.java +++ b/server/src/main/java/cn/keking/service/cache/impl/CacheServiceRedisImpl.java @@ -107,6 +107,7 @@ public class CacheServiceRedisImpl implements CacheService { cleanPdfCache(); cleanImgCache(); cleanPdfImgCache(); + cleanMediaConvertCache(); } @Override @@ -135,4 +136,9 @@ public class CacheServiceRedisImpl implements CacheService { RMapCache pdfImg = redissonClient.getMapCache(FILE_PREVIEW_PDF_IMGS_KEY); pdfImg.clear(); } + + private void cleanMediaConvertCache() { + RMapCache mediaConvertCache = redissonClient.getMapCache(FILE_PREVIEW_MEDIA_CONVERT_KEY); + mediaConvertCache.clear(); + } } diff --git a/server/src/main/java/cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java b/server/src/main/java/cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java index b038a52a..c10f997c 100644 --- a/server/src/main/java/cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java +++ b/server/src/main/java/cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java @@ -104,7 +104,7 @@ public class CacheServiceRocksDBImpl implements CacheService { @SuppressWarnings("unchecked") public Map getPDFCache() { Map result = new HashMap<>(); - try{ + try { result = (Map) toObject(db.get(FILE_PREVIEW_PDF_KEY.getBytes())); } catch (RocksDBException | IOException | ClassNotFoundException e) { LOGGER.error("Get from RocksDB Exception" + e); @@ -116,7 +116,7 @@ public class CacheServiceRocksDBImpl implements CacheService { @SuppressWarnings("unchecked") public String getPDFCache(String key) { String result = ""; - try{ + try { Map map = (Map) toObject(db.get(FILE_PREVIEW_PDF_KEY.getBytes())); result = map.get(key); } catch (RocksDBException | IOException | ClassNotFoundException e) { @@ -129,7 +129,7 @@ public class CacheServiceRocksDBImpl implements CacheService { @SuppressWarnings("unchecked") public Map> getImgCache() { Map> result = new HashMap<>(); - try{ + try { result = (Map>) toObject(db.get(FILE_PREVIEW_IMGS_KEY.getBytes())); } catch (RocksDBException | IOException | ClassNotFoundException e) { LOGGER.error("Get from RocksDB Exception" + e); @@ -142,7 +142,7 @@ public class CacheServiceRocksDBImpl implements CacheService { public List getImgCache(String key) { List result = new ArrayList<>(); Map> map; - try{ + try { map = (Map>) toObject(db.get(FILE_PREVIEW_IMGS_KEY.getBytes())); result = map.get(key); } catch (RocksDBException | IOException | ClassNotFoundException e) { @@ -156,7 +156,7 @@ public class CacheServiceRocksDBImpl implements CacheService { public Integer getPdfImageCache(String key) { Integer result = 0; Map map; - try{ + try { map = (Map) toObject(db.get(FILE_PREVIEW_PDF_IMGS_KEY.getBytes())); result = map.get(key); } catch (RocksDBException | IOException | ClassNotFoundException e) { @@ -180,7 +180,7 @@ public class CacheServiceRocksDBImpl implements CacheService { @SuppressWarnings("unchecked") public Map getMediaConvertCache() { Map result = new HashMap<>(); - try{ + try { result = (Map) toObject(db.get(FILE_PREVIEW_MEDIA_CONVERT_KEY.getBytes())); } catch (RocksDBException | IOException | ClassNotFoundException e) { LOGGER.error("Get from RocksDB Exception" + e); @@ -203,7 +203,7 @@ public class CacheServiceRocksDBImpl implements CacheService { @SuppressWarnings("unchecked") public String getMediaConvertCache(String key) { String result = ""; - try{ + try { Map map = (Map) toObject(db.get(FILE_PREVIEW_MEDIA_CONVERT_KEY.getBytes())); result = map.get(key); } catch (RocksDBException | IOException | ClassNotFoundException e) { @@ -218,6 +218,7 @@ public class CacheServiceRocksDBImpl implements CacheService { cleanPdfCache(); cleanImgCache(); cleanPdfImgCache(); + cleanMediaConvertCache(); } catch (IOException | RocksDBException e) { LOGGER.error("Clean Cache Exception" + e); } @@ -236,7 +237,7 @@ public class CacheServiceRocksDBImpl implements CacheService { @SuppressWarnings("unchecked") private Map getPdfImageCaches() { Map map = new HashMap<>(); - try{ + try { map = (Map) toObject(db.get(FILE_PREVIEW_PDF_IMGS_KEY.getBytes())); } catch (RocksDBException | IOException | ClassNotFoundException e) { LOGGER.error("Get from RocksDB Exception" + e); @@ -245,22 +246,22 @@ public class CacheServiceRocksDBImpl implements CacheService { } - private byte[] toByteArray (Object obj) throws IOException { + private byte[] toByteArray(Object obj) throws IOException { byte[] bytes; ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(obj); oos.flush(); - bytes = bos.toByteArray (); + bytes = bos.toByteArray(); oos.close(); bos.close(); return bytes; } - private Object toObject (byte[] bytes) throws IOException, ClassNotFoundException { + private Object toObject(byte[] bytes) throws IOException, ClassNotFoundException { Object obj; - ByteArrayInputStream bis = new ByteArrayInputStream (bytes); - ObjectInputStream ois = new ObjectInputStream (bis); + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ObjectInputStream(bis); obj = ois.readObject(); ois.close(); bis.close(); @@ -281,4 +282,9 @@ public class CacheServiceRocksDBImpl implements CacheService { Map initPDFIMGCache = new HashMap<>(); db.put(FILE_PREVIEW_PDF_IMGS_KEY.getBytes(), toByteArray(initPDFIMGCache)); } + + private void cleanMediaConvertCache() throws IOException, RocksDBException { + Map initMediaConvertCache = new HashMap<>(); + db.put(FILE_PREVIEW_MEDIA_CONVERT_KEY.getBytes(), toByteArray(initMediaConvertCache)); + } }