Commit 4626a92b authored by Liang Ding's avatar Liang Ding

页面静态化 #107

parent cc540d0b
......@@ -15,7 +15,6 @@ import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Singleton;
import org.b3log.solo.model.Article;
import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Statics;
import org.json.JSONObject;
import java.util.Map;
......@@ -79,7 +78,6 @@ public class ArticleCache {
public void putArticle(final JSONObject article) {
idCache.put(article.optString(Keys.OBJECT_ID), Solos.clone(article));
permalinkCache.put(article.optString(Article.ARTICLE_PERMALINK), Solos.clone(article));
Statics.clear();
}
/**
......@@ -95,7 +93,6 @@ public class ArticleCache {
final String permalink = article.optString(Article.ARTICLE_PERMALINK);
idCache.remove(id);
permalinkCache.remove(permalink);
Statics.clear();
}
/**
......@@ -104,6 +101,5 @@ public class ArticleCache {
public void clear() {
idCache.clear();
permalinkCache.clear();
Statics.clear();
}
}
\ No newline at end of file
......@@ -14,7 +14,6 @@ package org.b3log.solo.cache;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Singleton;
import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Statics;
import org.json.JSONObject;
import java.util.Map;
......@@ -57,7 +56,6 @@ public class CommentCache {
*/
public void putComment(final JSONObject comment) {
cache.put(comment.optString(Keys.OBJECT_ID), Solos.clone(comment));
Statics.clear();
}
/**
......@@ -67,7 +65,6 @@ public class CommentCache {
*/
public void removeComment(final String id) {
cache.remove(id);
Statics.clear();
}
/**
......@@ -75,6 +72,5 @@ public class CommentCache {
*/
public void clear() {
cache.clear();
Statics.clear();
}
}
......@@ -15,7 +15,6 @@ import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Singleton;
import org.b3log.solo.model.Option;
import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Statics;
import org.json.JSONObject;
import java.util.Map;
......@@ -73,7 +72,6 @@ public class OptionCache {
*/
public void putCategory(final String category, final JSONObject mergedOptions) {
categoryCache.put(category, mergedOptions);
Statics.clear();
}
/**
......@@ -101,8 +99,6 @@ public class OptionCache {
final String category = option.optString(Option.OPTION_CATEGORY);
removeCategory(category);
Statics.clear();
}
/**
......@@ -120,7 +116,6 @@ public class OptionCache {
removeCategory(category);
cache.remove(id);
Statics.clear();
}
/**
......@@ -129,6 +124,5 @@ public class OptionCache {
public void clear() {
cache.clear();
categoryCache.clear();
Statics.clear();
}
}
......@@ -14,7 +14,6 @@ package org.b3log.solo.cache;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Singleton;
import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Statics;
import org.json.JSONObject;
import java.util.Map;
......@@ -59,7 +58,6 @@ public class PageCache {
final String pageId = page.optString(Keys.OBJECT_ID);
cache.put(pageId, Solos.clone(page));
Statics.clear();
}
/**
......@@ -69,7 +67,6 @@ public class PageCache {
*/
public void removePage(final String id) {
cache.remove(id);
Statics.clear();
}
/**
......@@ -77,6 +74,5 @@ public class PageCache {
*/
public void clear() {
cache.clear();
Statics.clear();
}
}
......@@ -29,6 +29,7 @@ import org.b3log.latke.util.Requests;
import org.b3log.solo.model.UserExt;
import org.b3log.solo.service.*;
import org.b3log.solo.util.Solos;
import org.b3log.solo.util.Statics;
import org.json.JSONObject;
import java.util.Map;
......@@ -42,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
* </ul>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.0.0, Feb 9, 2020
* @version 2.0.0.1, Apr 14, 2020
* @since 2.9.5
*/
@Singleton
......@@ -195,6 +196,7 @@ public class OAuthProcessor {
}
Solos.login(user, response);
Statics.clear();
context.sendRedirect(referer);
LOGGER.log(Level.INFO, "Logged in [name={}, remoteAddr={}] with oauth", userName, Requests.getRemoteAddr(request));
}
......
......@@ -32,6 +32,7 @@ import org.b3log.solo.event.EventTypes;
import org.b3log.solo.model.*;
import org.b3log.solo.repository.*;
import org.b3log.solo.util.GitHubs;
import org.b3log.solo.util.Statics;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -471,6 +472,8 @@ public class ArticleMgmtService {
}
transaction.commit();
Statics.clear();
} catch (final ServiceException e) {
if (transaction.isActive()) {
transaction.rollback();
......@@ -565,6 +568,8 @@ public class ArticleMgmtService {
articleRepository.add(article);
transaction.commit();
Statics.clear();
article.put(Common.POST_TO_COMMUNITY, postToCommunity);
if (Article.ARTICLE_STATUS_C_PUBLISHED == article.optInt(ARTICLE_STATUS)) {
final JSONObject eventData = new JSONObject();
......@@ -596,6 +601,8 @@ public class ArticleMgmtService {
articleRepository.remove(articleId);
commentRepository.removeComments(articleId);
transaction.commit();
Statics.clear();
} catch (final Exception e) {
if (transaction.isActive()) {
transaction.rollback();
......
......@@ -75,6 +75,11 @@ public final class Statics {
* @return HTML, returns {@code null} if not found
*/
public static String get(final RequestContext context) {
if (Solos.isLoggedIn(context)) {
// 登录用户不走缓存
return null;
}
final String key = key(context);
if (null == key) {
return null;
......@@ -101,6 +106,11 @@ public final class Statics {
* @param context the specified context
*/
public static void put(final RequestContext context) {
if (Solos.isLoggedIn(context)) {
// 登录用户生成的内容不写入缓存
return;
}
final String key = key(context);
if (null == key) {
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment