package com.hardcode.sample.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.hardcode.sample.domain.Employee; import com.hardcode.sample.repository.EmployeeRepository; import lombok.extern.slf4j.Slf4j; @Service @Slf4j public class EmployeeService { @Autowired private EmployeeRepository repository; /** * This method returns an existing employee record. * @param id */ @Cacheable("employees") @Transactional(readOnly=true) public Employee findOne(Long id) { log.info("Find employee by id - {}", id); //Employee emp = new Employee(); //emp.setId(id); return repository.findOne(id); } @CachePut("employees") @Transactional public Employee save(Employee e){ return repository.save(e); } @CachePut("employees") @Transactional public Employee update(Employee e){ return repository.save(e); } }