From a5ccfcd3f3e8d96250c92638cf2f66736827ffbc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 9 Dec 2022 14:45:24 +0300 Subject: Better caching in AnythingFilter --- src/main/java/com/juick/service/UserService.java | 7 +++++-- src/main/java/com/juick/service/UserServiceImpl.java | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/main/java/com/juick/service') diff --git a/src/main/java/com/juick/service/UserService.java b/src/main/java/com/juick/service/UserService.java index a3ab8315..db02c34e 100644 --- a/src/main/java/com/juick/service/UserService.java +++ b/src/main/java/com/juick/service/UserService.java @@ -46,12 +46,15 @@ public interface UserService { String getSignUpHashByTelegramID(Long telegramId, String username); - @CacheEvict(value = "users_by_name", allEntries = true) + @CacheEvict(value = { "usernames", "users_by_name" }, allEntries = true) Optional createUser(String username, String password) throws UsernameTakenException; Optional getUserByUID(int uid); - @Cacheable(value = "users_by_name") + @Cacheable(value = "usernames") + List getUsernames(); + + @Cacheable(value = "users_by_name", key = "{ #username }") @Nonnull User getUserByName(String username); @Nonnull User getUserByEmail(String email); diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java index 71f2dc91..0e6f9606 100644 --- a/src/main/java/com/juick/service/UserServiceImpl.java +++ b/src/main/java/com/juick/service/UserServiceImpl.java @@ -173,6 +173,12 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { return AnonymousUser.INSTANCE; } + @Transactional(readOnly = true) + @Override + public List getUsernames() { + return getJdbcTemplate().queryForList("SELECT nick FROM users", String.class); + } + @Override @Transactional(readOnly = true) @Nonnull -- cgit v1.2.3