2017-05-31 110 views
2

我在春天的數據,如查詢結果:緩存查詢結果的ArrayList

public interface user extends extends CrudRepository<UserRegistration, Long> { 
@Query(value="select ur from UserRegistration ur where " 
     + " ur.location.id IN ?1 AND" 
     + " ur.event.id IN ?2") 
     public List<UserRegistration> getUsersBylocationAndEvent(long[] locationList, long[] eventList); 
} 

並使用服務實現此方法,因爲

public class userServiceImpl implements userService{ 
@Autowired 
UserRegistrationRepository userRegistrationRepository; 

@Override 
public List<UserRegistration> getUserRegistarationByEventAndLocation(long[] locationList, long[] eventList, int checkInFlag, Date checkInDate, int checkOutFlag, Date checkOutDate) { 
    List<UserRegistration> userRegistrationList = userRegistrationRepository.getUserRegByLocationIdsAndEvenIds(locationList, eventList); 

    return userRegistrationList; 
}} 

而且我用這個方法「getUserRegistarationByEventAndLocation ()「在多個web服務中,所以我想緩存第一個webservice在列表中調用時的結果,並且可以在其他webService中使用此列表。

+0

使列表成爲一個成員變量並檢查內容是否存在。不知道這是你在找什麼 – XtremeBaumer

回答

1

我們可以使用@Cacheable註釋。這可能有幫助

@Cacheable(value="UserRegistration") 
    List<UserRegistration> getUserRegByLocationIdsAndEvenIds(locationList, eventList); 
    { 

    }