forked from Fascinated/Bat
in-mem cache
This commit is contained in:
@ -5,6 +5,8 @@ import cc.fascinated.bat.repository.UserRepository;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -32,6 +34,7 @@ public class UserService {
|
||||
* @param id The ID of the user
|
||||
* @return The user
|
||||
*/
|
||||
@Cacheable(cacheNames = "users", key = "#id")
|
||||
public BatUser getUser(@NonNull String id) {
|
||||
long start = System.currentTimeMillis();
|
||||
Optional<BatUser> optionalUser = userRepository.findById(id);
|
||||
@ -48,6 +51,7 @@ public class UserService {
|
||||
*
|
||||
* @param user The user to save
|
||||
*/
|
||||
@CachePut(cacheNames = "users", key = "#user.id")
|
||||
public void saveUser(@NonNull BatUser user) {
|
||||
userRepository.save(user);
|
||||
}
|
||||
|
Reference in New Issue
Block a user