Commit 0bafb458 authored by Liang Ding's avatar Liang Ding

#12515 缓存重构

parent 85c3dfae
......@@ -18,19 +18,20 @@
package org.b3log.solo.cache;
import org.b3log.latke.Keys;
import org.b3log.latke.cache.Cache;
import org.b3log.latke.cache.CacheFactory;
import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.solo.model.Article;
import org.b3log.solo.util.JSONs;
import org.json.JSONObject;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Article cache.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.2.0.0, Sep 16, 2018
* @version 1.2.0.1, Sep 25, 2018
* @since 2.3.0
*/
@Named
......@@ -40,12 +41,12 @@ public class ArticleCache {
/**
* Article id cache.
*/
private Cache idCache = CacheFactory.getCache(Article.ARTICLES);
private Map<String, JSONObject> idCache = new ConcurrentHashMap<>();
/**
* Article permalink cache.
*/
private Cache permalinkCache = CacheFactory.getCache(Article.ARTICLE_PERMALINK);
private Map<String, JSONObject> permalinkCache = new ConcurrentHashMap<>();
/**
* Gets an article by the specified article id.
......@@ -100,7 +101,7 @@ public class ArticleCache {
* Clears all cached articles.
*/
public void clear() {
idCache.removeAll();
permalinkCache.removeAll();
idCache.clear();
permalinkCache.clear();
}
}
\ No newline at end of file
......@@ -18,19 +18,19 @@
package org.b3log.solo.cache;
import org.b3log.latke.Keys;
import org.b3log.latke.cache.Cache;
import org.b3log.latke.cache.CacheFactory;
import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.solo.model.Comment;
import org.b3log.solo.util.JSONs;
import org.json.JSONObject;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Comment cache.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, Sep 16, 2018
* @version 1.1.0.1, Sep 25, 2018
* @since 2.3.0
*/
@Named
......@@ -40,7 +40,7 @@ public class CommentCache {
/**
* Comment cache.
*/
private Cache cache = CacheFactory.getCache(Comment.COMMENTS);
private Map<String, JSONObject> cache = new ConcurrentHashMap<>();
/**
* Gets a comment by the specified comment id.
......@@ -79,6 +79,6 @@ public class CommentCache {
* Clears all cached comments.
*/
public void clear() {
cache.removeAll();
cache.clear();
}
}
......@@ -18,8 +18,6 @@
package org.b3log.solo.cache;
import org.b3log.latke.Keys;
import org.b3log.latke.cache.Cache;
import org.b3log.latke.cache.CacheFactory;
import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.solo.model.Option;
......@@ -33,7 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
* Option cache.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, Sep 19, 2018
* @version 1.1.0.1, Sep 25, 2018
* @since 2.3.0
*/
@Named
......@@ -43,7 +41,7 @@ public class OptionCache {
/**
* Option cache.
*/
private static final Cache CACHE = CacheFactory.getCache(Option.OPTIONS);
private static final Map<String, JSONObject> CACHE = new ConcurrentHashMap<>();
/**
* Category option caches.
......
......@@ -18,19 +18,19 @@
package org.b3log.solo.cache;
import org.b3log.latke.Keys;
import org.b3log.latke.cache.Cache;
import org.b3log.latke.cache.CacheFactory;
import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.solo.model.Page;
import org.b3log.solo.util.JSONs;
import org.json.JSONObject;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Page cache.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Jul 18, 2017
* @version 1.0.0.1, Sep 25, 2018
* @since 2.3.0
*/
@Named
......@@ -40,7 +40,7 @@ public class PageCache {
/**
* Page cache.
*/
private Cache cache = CacheFactory.getCache(Page.PAGES);
private Map<String, JSONObject> cache = new ConcurrentHashMap<>();
/**
* Gets a page by the specified page id.
......
......@@ -17,18 +17,19 @@
*/
package org.b3log.solo.cache;
import org.b3log.latke.cache.Cache;
import org.b3log.latke.cache.CacheFactory;
import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.solo.model.Option;
import org.json.JSONObject;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Statistic cache.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Sep 6, 2017
* @version 1.0.0.1, Sep 25, 2018
* @since 2.4.0
*/
@Named
......@@ -38,7 +39,7 @@ public class StatisticCache {
/**
* Statistic cache.
*/
private Cache cache = CacheFactory.getCache(Option.CATEGORY_C_STATISTIC);
private Map<String, JSONObject> cache = new ConcurrentHashMap<>();
/**
* Get the statistic.
......@@ -62,6 +63,6 @@ public class StatisticCache {
* Clears the statistic.
*/
public void clear() {
cache.removeAll();
cache.clear();
}
}
......@@ -18,8 +18,6 @@
package org.b3log.solo.cache;
import org.b3log.latke.Keys;
import org.b3log.latke.cache.Cache;
import org.b3log.latke.cache.CacheFactory;
import org.b3log.latke.ioc.inject.Named;
import org.b3log.latke.ioc.inject.Singleton;
import org.b3log.latke.model.Role;
......@@ -27,11 +25,14 @@ import org.b3log.latke.model.User;
import org.b3log.solo.util.JSONs;
import org.json.JSONObject;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* User cache.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, Aug 27, 2017
* @version 1.1.0.1, Sep 25, 2018
* @since 2.3.0
*/
@Named
......@@ -41,17 +42,17 @@ public class UserCache {
/**
* Id, User.
*/
private Cache idCache = CacheFactory.getCache(User.USERS + "ID");
private Map<String, JSONObject> idCache = new ConcurrentHashMap<>();
/**
* Email, User.
*/
private Cache emailCache = CacheFactory.getCache(User.USERS + "Email");
private Map<String, JSONObject> emailCache = new ConcurrentHashMap<>();
/**
* Admin user.
*/
private Cache adminCache = CacheFactory.getCache("adminUser");
private Map<String, JSONObject> adminCache = new ConcurrentHashMap<>();
/**
* Gets the admin user.
......
......@@ -25,8 +25,6 @@ import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Latkes;
import org.b3log.latke.cache.Cache;
import org.b3log.latke.cache.CacheFactory;
import org.b3log.latke.ioc.LatkeBeanManagerImpl;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
......@@ -42,6 +40,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.*;
......@@ -53,7 +52,7 @@ import java.util.concurrent.*;
* </p>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.3.1.0, Apr 20, 2018
* @version 2.3.1.1, Sep 25, 2018
* @since 0.4.5
*/
public final class Markdowns {
......@@ -71,7 +70,7 @@ public final class Markdowns {
/**
* Markdown cache.
*/
private static final Cache MD_CACHE = CacheFactory.getCache("markdown");
private static final Map<String, JSONObject> MD_CACHE = new ConcurrentHashMap<>();
/**
* Markdown to HTML timeout.
......@@ -108,8 +107,6 @@ public final class Markdowns {
public static boolean MARKED_AVAILABLE;
static {
MD_CACHE.setMaxCount(1024 * 10 * 4);
try {
final URL url = new URL(MARKED_ENGINE_URL);
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
......
......@@ -18,7 +18,6 @@
package org.b3log.solo;
import org.b3log.latke.Latkes;
import org.b3log.latke.cache.CacheFactory;
import org.b3log.latke.ioc.LatkeBeanManager;
import org.b3log.latke.ioc.Lifecycle;
import org.b3log.latke.ioc.config.Discoverer;
......@@ -78,12 +77,9 @@ public abstract class AbstractTestCase {
* <ul>
* <li>Clears all caches</li>
* </ul>
*
* @throws Exception
*/
@BeforeClass
public void afterClass() throws Exception {
CacheFactory.clearAll();
public void afterClass() {
}
/**
......
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