Announcement Announcement Module
No announcement yet.
Configuring Cache in spring 3.1 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring Cache in spring 3.1

    Please find the below code. I would like to store person and persons in same cache place,
    ex: whenever i hit Summary page, the records will cached, and if i try to open a record i would like to get the data from previously stored cache not from database.but i tried with googling to store an collection of objects with key , but i can't get the solution.

    Please help me in doing this.
    Thanks in advance..

    package com.sravan.service;

    import java.util.Collection;

    import javax.annotation.Resource;

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.cache.annotation.CacheEvict;
    import org.springframework.cache.annotation.CachePut;
    import org.springframework.cache.annotation.Cacheable;
    import org.springframework.stereotype.Service;

    import com.sravan.beans.Person;
    import com.sravan.dao.PersonDAO;
    public class PersonServiceImpl implements PersonService{
    private PersonDAO persondao;
    private final Logger logger = LoggerFactory.getLogger(getClass());
    public boolean deletePerson(Person person) {
    return this.persondao.deletePerson(person);
    public Person findById(int id) {
    Person person=this.persondao.getPersonById(id);
    logger.debug("person" +person.getPersonAddresses());
    return person;
    public Collection<Person> getAllPerson() {
    return this.persondao.getAllPerson();

    public Person savePerson(Person person) {
    logger.debug("while saving person");
    return person;
    else return new Person();
    public Person updatePerson(Person person) {
    return person;
    else return new Person();

  • #2
    Please use [ code][/code ] tags when posting code, that way it remains readable...

    Only adding the @Cache annotations isn't going to do anything you also need something to configure your cache. Also I'm not certain if it is possible to share this cache as both have different keys and store different things. It might be that, when you use for instance hibernate, enabling 2nd level caching on your ORM implemenation might make this work (this would mean you cannot use the @Cache annotation anymore but rely on your ORM provider).