Should I do caching at the DAO or service level in the Spring MVC web application?

I would like to cache data in my Spring MVC web application. Since I'm new to Spring and MVC architecture, I would like to ask if data should be cached (via Spring Caching System ) at the DAO level or should I cache service-level output methods?

eg. I have this method at the service level:

@Override
public LinkedList<OrderCount> getOrderCount(Date dateFrom, Date dateTo, Class type) {
    try {
        return chartDataDAO.getOrderCount(dateFrom, dateTo, type);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

and this method calls this DAO method:

public LinkedList<OrderCount> getOrderCount(Date dateFrom, Date dateTo, Class type);

My question is: do caching on the service or at the DAO level?

+5
source share
2 answers

-, . , . , ( - ).

-, , , , EHCache .. (, )

-, , , . getOrderCount(January 27, January 28, String) , getOrderCount(March 21, March 28, Vector). , -, , , , ( ) .

+6

, , - . , , - api , , Etag. ( ), , EhCache.

Spring, , DAO. , - - , , , ORM, , , .

+3

All Articles