Skip to content

Instantly share code, notes, and snippets.

@m-cakir
Last active September 28, 2017 10:37
Show Gist options
  • Select an option

  • Save m-cakir/eaf918293b16e7cc12b6f8544abcdfeb to your computer and use it in GitHub Desktop.

Select an option

Save m-cakir/eaf918293b16e7cc12b6f8544abcdfeb to your computer and use it in GitHub Desktop.
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