aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/API.java2
-rw-r--r--src/main/java/com/juick/config/WebConfig.java5
-rw-r--r--src/main/java/com/juick/service/EmailService.java3
-rw-r--r--src/main/java/com/juick/service/MessagesService.java7
-rw-r--r--src/main/java/com/juick/service/PrivacyQueriesService.java4
-rw-r--r--src/main/java/com/juick/service/SubscriptionService.java4
-rw-r--r--src/main/java/com/juick/service/TagService.java2
-rw-r--r--src/main/java/com/juick/service/UserService.java9
8 files changed, 31 insertions, 5 deletions
diff --git a/src/main/java/com/juick/API.java b/src/main/java/com/juick/API.java
index 79ec209d..755e4fc4 100644
--- a/src/main/java/com/juick/API.java
+++ b/src/main/java/com/juick/API.java
@@ -21,10 +21,12 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration;
+import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@EnableAutoConfiguration(exclude = { MailSenderAutoConfiguration.class })
+@EnableCaching
@ComponentScan(basePackages = {"com.juick.config", "com.juick.service", "com.juick.www"})
public class API {
public static void main(String[] args) {
diff --git a/src/main/java/com/juick/config/WebConfig.java b/src/main/java/com/juick/config/WebConfig.java
index bfebd77f..0c816712 100644
--- a/src/main/java/com/juick/config/WebConfig.java
+++ b/src/main/java/com/juick/config/WebConfig.java
@@ -40,7 +40,6 @@ import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
-import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
@@ -78,10 +77,6 @@ public class WebConfig implements WebMvcConfigurer {
public StorageService storageService() {
return new FileSystemStorageService(baseDir, tmpDir);
}
- @Bean
- public CaffeineCacheManager cacheManager() {
- return new CaffeineCacheManager("help");
- }
@Bean
public HelpService helpService() {
diff --git a/src/main/java/com/juick/service/EmailService.java b/src/main/java/com/juick/service/EmailService.java
index 158fae80..bdd7d405 100644
--- a/src/main/java/com/juick/service/EmailService.java
+++ b/src/main/java/com/juick/service/EmailService.java
@@ -19,12 +19,15 @@ package com.juick.service;
import com.juick.model.User;
+import org.springframework.cache.annotation.CacheEvict;
+
import java.util.List;
/**
* Created by vitalyster on 09.12.2016.
*/
public interface EmailService {
+ @CacheEvict(value = "users_by_name", allEntries = true)
boolean verifyAddressByCode(Integer userId, String code);
boolean addVerificationCode(Integer userId, String account, String code);
boolean addEmail(Integer userId, String email);
diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java
index d102031d..3fdd2b9e 100644
--- a/src/main/java/com/juick/service/MessagesService.java
+++ b/src/main/java/com/juick/service/MessagesService.java
@@ -23,6 +23,8 @@ import com.juick.model.User;
import com.juick.model.ResponseReply;
import com.juick.model.Tag;
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.*;
@@ -31,8 +33,10 @@ import java.util.*;
* Created by aalexeev on 11/13/16.
*/
public interface MessagesService {
+ @CacheEvict(value = { "discussions", "messages", "replies" }, allEntries = true)
int createMessage(int uid, String txt, String attachment, Set<Tag> tags);
+ @CacheEvict(value = { "discussions", "messages", "replies" }, allEntries = true)
int createReply(int mid, int rid, User user, String txt, String attachment);
enum RecommendStatus {
Error,
@@ -83,6 +87,7 @@ public interface MessagesService {
List<Integer> getPrivate(int uid, int before);
+ @Cacheable(value = "discussions", key="#uid + #to")
List<Integer> getDiscussions(int uid, Long to);
/**
@@ -111,10 +116,12 @@ public interface MessagesService {
List<Integer> getUserSearch(User visitor, int UID, String search, int privacy, int page);
+ @Cacheable(value = "messages", key="#visitor.uid + #mids.hashCode()")
List<Message> getMessages(User visitor, List<Integer> mids);
Map<Integer,Set<Reaction>> updateReactionsFor(final List<Integer> mid);
+ @Cacheable(value = "replies", key="#user.uid + #mid")
List<Message> getReplies(User user, int mid);
boolean setMessagePrivacy(int mid);
diff --git a/src/main/java/com/juick/service/PrivacyQueriesService.java b/src/main/java/com/juick/service/PrivacyQueriesService.java
index e4b1da25..68c157f6 100644
--- a/src/main/java/com/juick/service/PrivacyQueriesService.java
+++ b/src/main/java/com/juick/service/PrivacyQueriesService.java
@@ -20,6 +20,8 @@ package com.juick.service;
import com.juick.model.Tag;
import com.juick.model.User;
+import org.springframework.cache.annotation.CacheEvict;
+
/**
* Created by aalexeev on 11/13/16.
*/
@@ -28,7 +30,9 @@ public interface PrivacyQueriesService {
Removed, Added
}
+ @CacheEvict(value = { "discussions", "messages", "replies" }, allEntries = true)
PrivacyResult blacklistUser(User user, User target);
+ @CacheEvict(value = { "discussions", "messages", "replies" }, allEntries = true)
PrivacyResult blacklistTag(User user, Tag tag);
}
diff --git a/src/main/java/com/juick/service/SubscriptionService.java b/src/main/java/com/juick/service/SubscriptionService.java
index c12c9625..96735d1a 100644
--- a/src/main/java/com/juick/service/SubscriptionService.java
+++ b/src/main/java/com/juick/service/SubscriptionService.java
@@ -20,6 +20,9 @@ package com.juick.service;
import com.juick.model.Message;
import com.juick.model.Tag;
import com.juick.model.User;
+
+import org.springframework.cache.annotation.CacheEvict;
+
import com.juick.model.NotifyOpts;
import java.util.List;
@@ -37,6 +40,7 @@ public interface SubscriptionService {
List<User> getUsersSubscribedToUserRecommendations(int uid, Message msg);
+ @CacheEvict(value = { "discussions" }, allEntries = true)
boolean subscribeMessage(Message message, User user);
boolean unSubscribeMessage(int mid, int vuid);
diff --git a/src/main/java/com/juick/service/TagService.java b/src/main/java/com/juick/service/TagService.java
index 96e5975b..d04aacbc 100644
--- a/src/main/java/com/juick/service/TagService.java
+++ b/src/main/java/com/juick/service/TagService.java
@@ -21,6 +21,7 @@ import com.juick.model.Tag;
import com.juick.model.User;
import com.juick.model.TagStats;
import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.cache.annotation.Cacheable;
import java.util.Collection;
import java.util.List;
@@ -45,6 +46,7 @@ public interface TagService {
List<String> getUserBLTags(int uid);
+ @Cacheable(value = "popular_tags")
List<String> getPopularTags();
List<TagStats> getTagStats();
diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java
index 06637aee..a3ab8315 100644
--- a/src/main/java/com/juick/service/UserService.java
+++ b/src/main/java/com/juick/service/UserService.java
@@ -25,6 +25,8 @@ import com.juick.model.ExternalToken;
import com.juick.util.UsernameTakenException;
import org.apache.commons.lang3.tuple.Pair;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
import javax.annotation.Nonnull;
import java.util.Collection;
@@ -44,10 +46,12 @@ public interface UserService {
String getSignUpHashByTelegramID(Long telegramId, String username);
+ @CacheEvict(value = "users_by_name", allEntries = true)
Optional<User> createUser(String username, String password) throws UsernameTakenException;
Optional<User> getUserByUID(int uid);
+ @Cacheable(value = "users_by_name")
@Nonnull User getUserByName(String username);
@Nonnull User getUserByEmail(String email);
@@ -69,6 +73,7 @@ public interface UserService {
Optional<User> checkPassword(String username, String password);
+ @CacheEvict(value = "users_by_name", allEntries = true)
boolean updatePassword(User user, String newPassword);
int getUserOptionInt(int uid, String option, int defaultValue);
@@ -174,16 +179,20 @@ public interface UserService {
String getTelegramNameByHash(String hash);
+ @CacheEvict(value = "users_by_name", allEntries = true)
boolean setFacebookUser(String hash, int uid);
String getVKNameByHash(String hash);
+ @CacheEvict(value = "users_by_name", allEntries = true)
boolean setVKUser(String hash, int uid);
+ @CacheEvict(value = "users_by_name", allEntries = true)
boolean setTelegramUser(String hash, int uid);
String getJIDByHash(String hash);
+ @CacheEvict(value = "users_by_name", allEntries = true)
boolean setJIDUser(String hash, int uid);
boolean canDeleteTelegramUser(User user);