diff --git a/src/main/java/org/jasig/portlet/newsreader/dao/HibernateNewsStore.java b/src/main/java/org/jasig/portlet/newsreader/dao/HibernateNewsStore.java index 06abd1d1..b1993a9d 100644 --- a/src/main/java/org/jasig/portlet/newsreader/dao/HibernateNewsStore.java +++ b/src/main/java/org/jasig/portlet/newsreader/dao/HibernateNewsStore.java @@ -32,8 +32,11 @@ import org.jasig.portlet.newsreader.PredefinedNewsConfiguration; import org.jasig.portlet.newsreader.PredefinedNewsDefinition; import org.jasig.portlet.newsreader.UserDefinedNewsConfiguration; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; +import org.springframework.cache.annotation.Cacheable; + /** * HibernateNewsStore provides a hibernate implementation of the NewsStore. * @@ -277,6 +280,7 @@ public void deleteNewsDefinition(PredefinedNewsDefinition definition) { } } + @Cacheable("HibernateNewsStore.userRoles") public List getUserRoles() { try { @@ -291,6 +295,7 @@ public List getUserRoles() { } } + @Cacheable("HibernateNewsStore.newsSetById") public NewsSet getNewsSet(Long id) { try { @@ -303,6 +308,7 @@ public NewsSet getNewsSet(Long id) { } + @Cacheable("HibernateNewsStore.newsSetByUser") public List getNewsSetsForUser(String userId) { try { @@ -317,6 +323,11 @@ public List getNewsSetsForUser(String userId) { } } + @CacheEvict(cacheNames = { + "HibernateNewsStore.newsSetById", + "HibernateNewsStore.newsSetByUser", + "HibernateNewsStore.newsSetByUserAndName" + }) public void storeNewsSet(NewsSet set) { try { @@ -328,6 +339,7 @@ public void storeNewsSet(NewsSet set) { } } + @Cacheable("HibernateNewsStore.newsSetByUserAndName") public NewsSet getNewsSet(String userId, String setName) { try { diff --git a/src/main/java/org/jasig/portlet/newsreader/service/SharedNewsSetServiceImpl.java b/src/main/java/org/jasig/portlet/newsreader/service/SharedNewsSetServiceImpl.java index aa8eec05..5c953820 100644 --- a/src/main/java/org/jasig/portlet/newsreader/service/SharedNewsSetServiceImpl.java +++ b/src/main/java/org/jasig/portlet/newsreader/service/SharedNewsSetServiceImpl.java @@ -52,8 +52,8 @@ public void setNewsStore(NewsStore newsStore) { /* * Get the news set from the ID or search the dataabse for a suitable set or create a new * set if one cannot be found. - * - * Initalise the NewsSet + * + * Initalise the NewsSet */ public NewsSet getNewsSet(String fname, PortletRequest request) { @@ -64,11 +64,11 @@ public NewsSet getNewsSet(String fname, PortletRequest request) { final String userId = userIdService.getUserId(request); NewsSet set; - + final Object mutex = PortletUtils.getSessionMutex(session); synchronized (mutex) { logger.debug("Got Mutex {} for userId={}", mutex, userId); - + set = newsStore.getNewsSet(userId, fname); if (set == null) { @@ -77,8 +77,9 @@ public NewsSet getNewsSet(String fname, PortletRequest request) { set.setUserId(userId); set.setName(fname); newsStore.storeNewsSet(set); - } - + set = newsStore.getNewsSet(userId, fname); // get set_id + } + // Persistent set is now loaded but may still need re-initalising since last use. // by adding setId to session, we signal that initialisation has taken place. if (session.getAttribute("setId", PortletSession.PORTLET_SCOPE) == null) { diff --git a/src/main/resources/context/applicationContext.xml b/src/main/resources/context/applicationContext.xml index dc667837..13385de8 100644 --- a/src/main/resources/context/applicationContext.xml +++ b/src/main/resources/context/applicationContext.xml @@ -25,9 +25,11 @@ xmlns:util="http://www.springframework.org/schema/util" xmlns:c="http://www.springframework.org/schema/c" xmlns:p="http://www.springframework.org/schema/p" + xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd + http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> - - + + + + + + + p:cacheManager-ref="cacheManagerFactory" p:cacheName="newsCache"/> @@ -149,12 +158,12 @@ - + - + diff --git a/src/main/resources/ehcache.xml b/src/main/resources/ehcache.xml index a957fe0c..b582f62a 100644 --- a/src/main/resources/ehcache.xml +++ b/src/main/resources/ehcache.xml @@ -35,7 +35,20 @@ memoryStoreEvictionPolicy="LRU"/> - - \ No newline at end of file + + + + + + +