Skip to content

Commit fcd76d3

Browse files
committed
🎨 b3log#12319 命名重构
1 parent 6bcd7fe commit fcd76d3

File tree

5 files changed

+22
-38
lines changed

5 files changed

+22
-38
lines changed

src/main/java/org/b3log/solo/cache/ArticleCache.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ public class ArticleCache {
3838
/**
3939
* Article cache.
4040
*/
41-
private static final Cache ARTICLE_CACHE = CacheFactory.getCache(Article.ARTICLES);
42-
43-
static {
44-
ARTICLE_CACHE.setMaxCount(128);
45-
}
41+
private Cache cache = CacheFactory.getCache(Article.ARTICLES);
4642

4743
/**
4844
* Gets an article by the specified article id.
@@ -51,7 +47,7 @@ public class ArticleCache {
5147
* @return article, returns {@code null} if not found
5248
*/
5349
public JSONObject getArticle(final String id) {
54-
final JSONObject article = ARTICLE_CACHE.get(id);
50+
final JSONObject article = cache.get(id);
5551
if (null == article) {
5652
return null;
5753
}
@@ -67,7 +63,7 @@ public JSONObject getArticle(final String id) {
6763
public void putArticle(final JSONObject article) {
6864
final String articleId = article.optString(Keys.OBJECT_ID);
6965

70-
ARTICLE_CACHE.put(articleId, JSONs.clone(article));
66+
cache.put(articleId, JSONs.clone(article));
7167
}
7268

7369
/**
@@ -76,6 +72,6 @@ public void putArticle(final JSONObject article) {
7672
* @param id the specified article id
7773
*/
7874
public void removeArticle(final String id) {
79-
ARTICLE_CACHE.remove(id);
75+
cache.remove(id);
8076
}
8177
}

src/main/java/org/b3log/solo/cache/CommentCache.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ public class CommentCache {
3838
/**
3939
* Comment cache.
4040
*/
41-
private static final Cache cache = CacheFactory.getCache(Comment.COMMENTS);
42-
43-
static {
44-
cache.setMaxCount(512);
45-
}
41+
private Cache cache = CacheFactory.getCache(Comment.COMMENTS);
4642

4743
/**
4844
* Gets a comment by the specified comment id.

src/main/java/org/b3log/solo/cache/OptionCache.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ public class OptionCache {
3838
/**
3939
* Option cache.
4040
*/
41-
private static final Cache CACHE = CacheFactory.getCache(Option.OPTIONS);
42-
43-
static {
44-
CACHE.setMaxCount(512);
45-
}
41+
private Cache CACHE = CacheFactory.getCache(Option.OPTIONS);
4642

4743
/**
4844
* Gets an option by the specified option id.

src/main/java/org/b3log/solo/cache/PageCache.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ public class PageCache {
3838
/**
3939
* Page cache.
4040
*/
41-
private static final Cache PAGE_CACHE = CacheFactory.getCache(Page.PAGES);
42-
43-
static {
44-
PAGE_CACHE.setMaxCount(128);
45-
}
41+
private Cache cache = CacheFactory.getCache(Page.PAGES);
4642

4743
/**
4844
* Gets a page by the specified page id.
@@ -51,7 +47,7 @@ public class PageCache {
5147
* @return page, returns {@code null} if not found
5248
*/
5349
public JSONObject getPage(final String id) {
54-
final JSONObject page = PAGE_CACHE.get(id);
50+
final JSONObject page = cache.get(id);
5551
if (null == page) {
5652
return null;
5753
}
@@ -67,7 +63,7 @@ public JSONObject getPage(final String id) {
6763
public void putPage(final JSONObject page) {
6864
final String pageId = page.optString(Keys.OBJECT_ID);
6965

70-
PAGE_CACHE.put(pageId, JSONs.clone(page));
66+
cache.put(pageId, JSONs.clone(page));
7167
}
7268

7369
/**
@@ -76,6 +72,6 @@ public void putPage(final JSONObject page) {
7672
* @param id the specified page id
7773
*/
7874
public void removePage(final String id) {
79-
PAGE_CACHE.remove(id);
75+
cache.remove(id);
8076
}
8177
}

src/main/java/org/b3log/solo/cache/UserCache.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ public class UserCache {
3939
/**
4040
* Id, User.
4141
*/
42-
private static final Cache ID_CACHE = CacheFactory.getCache(User.USERS + "ID");
42+
private Cache idCache = CacheFactory.getCache(User.USERS + "ID");
4343

4444
/**
4545
* Email, User.
4646
*/
47-
private static final Cache EMAIL_CACHE = CacheFactory.getCache(User.USERS + "Email");
47+
private Cache emailCache = CacheFactory.getCache(User.USERS + "Email");
4848

4949
/**
5050
* Admin user.
5151
*/
52-
private static final Cache ADMIN_CACHE = CacheFactory.getCache("adminUser");
52+
private Cache adminCache = CacheFactory.getCache("adminUser");
5353

5454
/**
5555
* Gets the admin user.
5656
*
5757
* @return admin user
5858
*/
5959
public JSONObject getAdmin() {
60-
return ADMIN_CACHE.get(Role.ADMIN_ROLE);
60+
return adminCache.get(Role.ADMIN_ROLE);
6161
}
6262

6363
/**
@@ -66,7 +66,7 @@ public JSONObject getAdmin() {
6666
* @param admin the specified admin user
6767
*/
6868
public void putAdmin(final JSONObject admin) {
69-
ADMIN_CACHE.put(Role.ADMIN_ROLE, admin);
69+
adminCache.put(Role.ADMIN_ROLE, admin);
7070
}
7171

7272
/**
@@ -76,7 +76,7 @@ public void putAdmin(final JSONObject admin) {
7676
* @return user, returns {@code null} if not found
7777
*/
7878
public JSONObject getUser(final String userId) {
79-
final JSONObject user = ID_CACHE.get(userId);
79+
final JSONObject user = idCache.get(userId);
8080
if (null == user) {
8181
return null;
8282
}
@@ -91,7 +91,7 @@ public JSONObject getUser(final String userId) {
9191
* @return user, returns {@code null} if not found
9292
*/
9393
public JSONObject getUserByEmail(final String userEmail) {
94-
final JSONObject user = EMAIL_CACHE.get(userEmail);
94+
final JSONObject user = emailCache.get(userEmail);
9595
if (null == user) {
9696
return null;
9797
}
@@ -105,8 +105,8 @@ public JSONObject getUserByEmail(final String userEmail) {
105105
* @param user the specified user
106106
*/
107107
public void putUser(final JSONObject user) {
108-
ID_CACHE.put(user.optString(Keys.OBJECT_ID), JSONs.clone(user));
109-
EMAIL_CACHE.put(user.optString(User.USER_EMAIL), JSONs.clone(user));
108+
idCache.put(user.optString(Keys.OBJECT_ID), JSONs.clone(user));
109+
emailCache.put(user.optString(User.USER_EMAIL), JSONs.clone(user));
110110
}
111111

112112
/**
@@ -115,14 +115,14 @@ public void putUser(final JSONObject user) {
115115
* @param id the specified user id
116116
*/
117117
public void removeUser(final String id) {
118-
final JSONObject user = ID_CACHE.get(id);
118+
final JSONObject user = idCache.get(id);
119119
if (null == user) {
120120
return;
121121
}
122122

123-
ID_CACHE.remove(id);
123+
idCache.remove(id);
124124

125125
final String email = user.optString(User.USER_EMAIL);
126-
EMAIL_CACHE.remove(email);
126+
emailCache.remove(email);
127127
}
128128
}

0 commit comments

Comments
 (0)