diff --git a/src/main/java/com/tale/service/ContentsService.java b/src/main/java/com/tale/service/ContentsService.java index 3e1d63de..4854a82e 100644 --- a/src/main/java/com/tale/service/ContentsService.java +++ b/src/main/java/com/tale/service/ContentsService.java @@ -10,6 +10,7 @@ import com.tale.model.entity.Contents; import com.tale.model.entity.Relationships; import com.tale.model.params.ArticleParam; +import com.tale.utils.TaleUtils; import com.vdurmont.emoji.EmojiParser; import io.github.biezhi.anima.Anima; import io.github.biezhi.anima.core.AnimaQuery; @@ -104,6 +105,8 @@ public void updateArticle(Contents contents) { metasService.saveMetas(cid, tags, Types.TAG); metasService.saveMetas(cid, categories, Types.CATEGORY); + //clear cache + TaleUtils.cache.clean(); } /** @@ -117,6 +120,8 @@ public void delete(int cid) { deleteById(Contents.class, cid); Anima.delete().from(Relationships.class).where(Relationships::getCid, cid).execute(); Anima.delete().from(Comments.class).where(Comments::getCid, cid).execute(); + //clear cache + TaleUtils.cache.clean(); } } diff --git a/src/main/java/com/tale/utils/TaleUtils.java b/src/main/java/com/tale/utils/TaleUtils.java index 01f5b5a2..a2d0fd8f 100644 --- a/src/main/java/com/tale/utils/TaleUtils.java +++ b/src/main/java/com/tale/utils/TaleUtils.java @@ -60,6 +60,7 @@ public class TaleUtils { Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE); private static final Pattern SLUG_REGEX = Pattern.compile("^[A-Za-z0-9_-]{3,50}$", Pattern.CASE_INSENSITIVE); + public static MapCache cache = MapCache.single(); /** * 设置记住密码 cookie @@ -149,6 +150,11 @@ public static String mdToHtml(String markdown) { if (StringKit.isBlank(markdown)) { return ""; } + + String cacheContent = cache.get(String.valueOf(markdown.hashCode())); + if(cacheContent != null){ + return cacheContent; + } List extensions = Collections.singletonList(TablesExtension.create()); Parser parser = Parser.builder().extensions(extensions).build(); @@ -168,6 +174,7 @@ public static String mdToHtml(String markdown) { if (TaleConst.BCONF.getBoolean(ENV_SUPPORT_GIST, true) && content.contains(GIST_PREFIX_URL)) { content = content.replaceAll(GIST_REG_PATTERN, GIST_REPLATE_PATTERN); } + cache.set(String.valueOf(markdown.hashCode()),content,-1); return content; }