I\'m trying to call a @Cacheable method from within the same class:
@Cacheable(value = \"defaultCache\", key = \"#id\")
public Person findPerson
Here is what I do for small projects with only marginal usage of method calls within the same class. In-code documentation is strongly advidsed, as it may look strage to colleagues. But its easy to test, simple, quick to achieve and spares me the full blown AspectJ instrumentation. However, for more heavy usage I'd advice the AspectJ solution.
@Service
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
class PersonDao {
private final PersonDao _personDao;
@Autowired
public PersonDao(PersonDao personDao) {
_personDao = personDao;
}
@Cacheable(value = "defaultCache", key = "#id")
public Person findPerson(int id) {
return getSession().getPerson(id);
}
public List findPersons(int[] ids) {
List list = new ArrayList();
for (int id : ids) {
list.add(_personDao.findPerson(id));
}
return list;
}
}