Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

ISSUE 559 #560

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/tale/service/ContentsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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();
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/tale/utils/TaleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Extension> extensions = Collections.singletonList(TablesExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
Expand All @@ -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;
}

Expand Down