Last active
September 28, 2017 10:37
-
-
Save m-cakir/eaf918293b16e7cc12b6f8544abcdfeb to your computer and use it in GitHub Desktop.
Medium post gist https://medium.com/@mcakir/spring-boot-redis-72c956612e3f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.mcakir.bootiful.services; | |
| import com.mcakir.bootiful.models.Movie; | |
| import com.mcakir.bootiful.repositories.MovieRepository; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.cache.annotation.CacheEvict; | |
| import org.springframework.cache.annotation.CachePut; | |
| import org.springframework.cache.annotation.Cacheable; | |
| import org.springframework.stereotype.Service; | |
| import java.util.List; | |
| @Service | |
| public class MovieService implements IMovieService { | |
| @Autowired | |
| MovieRepository movieRepository; | |
| @Cacheable(cacheNames = "movies") | |
| @Override | |
| public List<Movie> findAll() { | |
| return movieRepository.findAll(); | |
| } | |
| @Cacheable(cacheNames = "movie", key = "'movie#' + #id") | |
| @Override | |
| public Movie findOne(Long id) { | |
| return movieRepository.findOne(id); | |
| } | |
| @CachePut(cacheNames = "movie", key = "'movie#' + #movie.id") | |
| @CacheEvict(cacheNames = "movies", allEntries = true) | |
| @Override | |
| public Movie newOne(Movie movie) { | |
| return movieRepository.save(movie); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment