aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-08-02 13:37:51 +0300
committerGravatar Vitaly Takmazov2019-08-02 13:37:51 +0300
commitc8eeadee42695ed67dac47dbb9d7a66a1c9a8c6d (patch)
tree96a7d3a195fa953ecbb4637a429cbb740ac578a3 /src/main/java/com/juick
parent201d5d69beb431724de05908e7dabecacd6e68d7 (diff)
Caching configuration for users and discussions
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/server/configuration/WwwAppConfiguration.java5
-rw-r--r--src/main/java/com/juick/service/MessagesService.java5
-rw-r--r--src/main/java/com/juick/service/UserService.java5
3 files changed, 12 insertions, 3 deletions
diff --git a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java
index 635302c7..0c5c8dbf 100644
--- a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java
+++ b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java
@@ -32,6 +32,7 @@ import org.commonmark.node.Link;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
@@ -61,8 +62,8 @@ public class WwwAppConfiguration implements WebMvcConfigurer {
@Value("${img_path:#{systemEnvironment['TEMP'] ?: '/tmp'}}")
private String imgDir;
@Bean
- public CaffeineCacheManager cacheManager() {
- return new CaffeineCacheManager("help");
+ public CacheManager cacheManager() {
+ return new CaffeineCacheManager("help", "users_by_name", "discussions");
}
@Bean
diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java
index e98b2b1d..490e0cfc 100644
--- a/src/main/java/com/juick/service/MessagesService.java
+++ b/src/main/java/com/juick/service/MessagesService.java
@@ -22,6 +22,8 @@ import com.juick.Reaction;
import com.juick.User;
import com.juick.model.ResponseReply;
import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
import java.net.URI;
import java.util.*;
@@ -30,8 +32,10 @@ import java.util.*;
* Created by aalexeev on 11/13/16.
*/
public interface MessagesService {
+ @CacheEvict(value = "discussions", allEntries = true)
int createMessage(int uid, String txt, String attachment, List<com.juick.Tag> tags);
+ @CacheEvict(value = "discussions", allEntries = true)
int createReply(int mid, int rid, User user, String txt, String attachment);
int getReplyIDIncrement(int mid);
@@ -83,6 +87,7 @@ public interface MessagesService {
List<Integer> getPrivate(int uid, int before);
+ @Cacheable(value = "discussions", key="#uid")
List<Integer> getDiscussions(int uid, Long to);
List<Integer> getRecommended(int uid, int before);
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index 0d4efcfc..63b75110 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -20,9 +20,10 @@ package com.juick.service;
import com.juick.Message;
import com.juick.User;
import com.juick.model.Auth;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
import javax.annotation.Nonnull;
-import java.time.Instant;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
@@ -40,10 +41,12 @@ public interface UserService {
String getSignUpHashByTelegramID(Long telegramId, String username);
+ @CacheEvict(value = "users_by_name", allEntries = true)
Optional<User> createUser(String username, String password);
Optional<User> getUserByUID(int uid);
+ @Cacheable(value = "users_by_name")
@Nonnull User getUserByName(String username);
@Nonnull User getUserByEmail(String email);