Browse Source

like更新缓存

wangqifan 4 years ago
parent
commit
b480d86658
1 changed files with 2 additions and 0 deletions
  1. 2 0
      src/main/java/com/izouma/nineth/repo/ShowroomRepo.java

+ 2 - 0
src/main/java/com/izouma/nineth/repo/ShowroomRepo.java

@@ -1,6 +1,7 @@
 package com.izouma.nineth.repo;
 
 import com.izouma.nineth.domain.Showroom;
+import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@@ -20,6 +21,7 @@ public interface ShowroomRepo extends JpaRepository<Showroom, Long>, JpaSpecific
     @Query("update Showroom t set t.likes = t.likes + ?2 where t.id = ?1")
     @Modifying
     @Transactional
+    @CacheEvict(value = "showroom", key = "#id")
     void addLike(Long id, int num);
 
     Optional<Showroom> findByUserIdAndType(Long userId, String type);