Commit d728e701 authored by Liang Ding's avatar Liang Ding

页面静态化 #107

parent 36bf7d7e
......@@ -15,6 +15,7 @@ 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;
......@@ -78,6 +79,7 @@ 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();
}
/**
......@@ -93,6 +95,7 @@ public class ArticleCache {
final String permalink = article.optString(Article.ARTICLE_PERMALINK);
idCache.remove(id);
permalinkCache.remove(permalink);
Statics.clear();
}
/**
......@@ -101,5 +104,6 @@ public class ArticleCache {
public void clear() {
idCache.clear();
permalinkCache.clear();
Statics.clear();
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ 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;
......@@ -56,6 +57,7 @@ public class CommentCache {
*/
public void putComment(final JSONObject comment) {
cache.put(comment.optString(Keys.OBJECT_ID), Solos.clone(comment));
Statics.clear();
}
/**
......@@ -65,6 +67,7 @@ public class CommentCache {
*/
public void removeComment(final String id) {
cache.remove(id);
Statics.clear();
}
/**
......@@ -72,5 +75,6 @@ public class CommentCache {
*/
public void clear() {
cache.clear();
Statics.clear();
}
}
......@@ -15,6 +15,7 @@ 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;
......@@ -72,6 +73,7 @@ public class OptionCache {
*/
public void putCategory(final String category, final JSONObject mergedOptions) {
categoryCache.put(category, mergedOptions);
Statics.clear();
}
/**
......@@ -99,6 +101,8 @@ public class OptionCache {
final String category = option.optString(Option.OPTION_CATEGORY);
removeCategory(category);
Statics.clear();
}
/**
......@@ -116,6 +120,7 @@ public class OptionCache {
removeCategory(category);
cache.remove(id);
Statics.clear();
}
/**
......@@ -124,5 +129,6 @@ public class OptionCache {
public void clear() {
cache.clear();
categoryCache.clear();
Statics.clear();
}
}
......@@ -14,6 +14,7 @@ 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;
......@@ -58,6 +59,7 @@ public class PageCache {
final String pageId = page.optString(Keys.OBJECT_ID);
cache.put(pageId, Solos.clone(page));
Statics.clear();
}
/**
......@@ -67,6 +69,7 @@ public class PageCache {
*/
public void removePage(final String id) {
cache.remove(id);
Statics.clear();
}
/**
......@@ -74,5 +77,6 @@ public class PageCache {
*/
public void clear() {
cache.clear();
Statics.clear();
}
}
......@@ -13,7 +13,6 @@ package org.b3log.solo.util;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
......@@ -35,7 +34,7 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* Static utilities.
* Static utilities. 页面静态化 https://github.com/88250/solo/issues/107
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Apr 14, 2020
......@@ -129,28 +128,12 @@ public final class Statics {
}
}
private static File[] files;
/**
* Gets static HTML randomly.
*
* @return HTML
*/
public static String random() {
if (null == DIR) {
return null;
}
if (null == files) {
files = DIR.listFiles();
if (null == files) {
return null;
}
public static void clear() {
try {
FileUtils.cleanDirectory(DIR);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Clears static cached files failed", e);
}
final File file = files[RandomUtils.nextInt(files.length)];
return readFile(file);
}
private static String readFile(final File file) {
......
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