cloudstore-aplcache
Details
docker-compose.yml 10(+3 -7)
diff --git a/docker-compose.yml b/docker-compose.yml
index 7044a5f..b764c70 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -10,15 +10,11 @@ services:
command: bash -c 'while !</dev/tcp/database/3306; do sleep 5; done; bash run.sh'
environment:
- JAVA_OPTS=${JAVA_OPTS:-"-Xms4096m -Xmx6124m"}
- - TRACER_ENABLE=${TRACER_ENABLE:-true}
- - TRACER_MINIMUM_EXECUTION_TIME=${TRACER_MINIMUM_EXECUTION_TIME:-1}
+ - CACHE_EVENTS=${CACHE_EVENTS:-/caching-approaches-comparison/applications/output/cloudstore-aplcache-cache}
+ - CACHE_REGISTER_SIZE=false
+ - APLCACHE_CACHEABLE_PARAMETERS=/caching-approaches-comparison/applications/output/aplcache-cloudstore-parameters.json
- TRACER_SERIALISE_INTERNALS=false
- - TRACER_VERBOSE=true
- - TRACER_TRACES=/caching-approaches-comparison/applications/traces/cloudstore
- - TRACER_LOG=/caching-approaches-comparison/applications/output/cloudstore-tracer.log
- - TRACER_BLACKLIST=/caching-approaches-comparison/applications/uncached/cloudstore/blacklist
- TRACER_IGNORED_PACKAGES=/caching-approaches-comparison/applications/uncached/cloudstore/ignored
- - TRACER_WHITELIST=/caching-approaches-comparison/applications/uncached/cloudstore/whitelist
volumes:
- application:/application
- /root/.m2:/root/.m2
pom.xml 62(+10 -52)
diff --git a/pom.xml b/pom.xml
index 649e568..35bfa1c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -187,62 +187,20 @@
</dependency>
<dependency>
- <groupId>br.ufrgs.inf.prosoft.applicationtracer</groupId>
- <artifactId>ApplicationTracer</artifactId>
+ <groupId>br.ufrgs.inf.prosoft.cache</groupId>
+ <artifactId>Cache</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>br.ufrgs.inf.prosoft.aplcache</groupId>
+ <artifactId>APLCache</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>aspectj-maven-plugin</artifactId>
- <version>1.11</version>
- <configuration>
- <showWeaveInfo>false</showWeaveInfo>
- <complianceLevel>1.8</complianceLevel>
- <source>1.6</source>
- <target>1.6</target>
- <Xlint>ignore</Xlint>
- <encoding>UTF-8</encoding>
- <verbose>false</verbose>
- <forceAjcCompile>true</forceAjcCompile>
- <sources/>
- <weaveDirectories>
- <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
- </weaveDirectories>
- <aspectLibraries>
- <aspectLibrary>
- <groupId>br.ufrgs.inf.prosoft.applicationtracer</groupId>
- <artifactId>ApplicationTracer</artifactId>
- </aspectLibrary>
- </aspectLibraries>
- </configuration>
- <executions>
- <execution>
- <phase>process-classes</phase>
- <goals>
- <goal>compile</goal>
- </goals>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
- <version>1.9.1</version>
- </dependency>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjtools</artifactId>
- <version>1.9.1</version>
- </dependency>
- </dependencies>
- </plugin>
-
-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
@@ -341,8 +299,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
+ <source>1.8</source>
+ <target>1.8</target>
<!-- <compilerArgument>-Xlint:all</compilerArgument> -->
<!-- <showWarnings>true</showWarnings> -->
<!-- <showDeprecation>true</showDeprecation> -->
diff --git a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/CustomerDaoImpl.java b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/CustomerDaoImpl.java
index f5d5ef7..b042bb2 100755
--- a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/CustomerDaoImpl.java
+++ b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/CustomerDaoImpl.java
@@ -9,6 +9,8 @@
*******************************************************************************/
package eu.cloudscale.showcase.db.dao.hibernate.impl;
+import br.ufrgs.inf.prosoft.aplcache.caching.APLCache;
+
import java.util.List;
import org.hibernate.Query;
@@ -39,22 +41,26 @@ public class CustomerDaoImpl extends DaoImpl<ICustomer> implements ICustomerDao
super( sessionFactory );
}
+ public static APLCache<ICustomer> getUserByCache = new APLCache<>("CustomerDaoImpl.getUserBy");
+
@SuppressWarnings( "rawtypes" )
@Override
public ICustomer getUserBy(String username, String password)
{
- String query = "SELECT C FROM Customer as C WHERE C.CUname = :username AND C.CPasswd = :passwd";
-
- Query q = getCurrentSession().createQuery( query );
- q.setMaxResults( 1 );
- q.setParameter( "username", username );
- q.setParameter( "passwd", password );
- List res = q.list();
-
- if( res.isEmpty() )
- return null;
-
- return (ICustomer) res.get( 0 );
+ return getUserByCache.computeIfAbsent(Thread.currentThread(), new Object[]{username, password}, () -> {
+ String query = "SELECT C FROM Customer as C WHERE C.CUname = :username AND C.CPasswd = :passwd";
+
+ Query q = getCurrentSession().createQuery( query );
+ q.setMaxResults( 1 );
+ q.setParameter( "username", username );
+ q.setParameter( "passwd", password );
+ List res = q.list();
+
+ if( res.isEmpty() )
+ return null;
+
+ return (ICustomer) res.get( 0 );
+ }, 86400000);
}
diff --git a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ItemDaoImpl.java b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ItemDaoImpl.java
index c087c62..d6525c4 100755
--- a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ItemDaoImpl.java
+++ b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ItemDaoImpl.java
@@ -13,6 +13,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
+import br.ufrgs.inf.prosoft.aplcache.caching.APLCache;
+
// import org.hibernate.CacheMode;
import org.hibernate.Hibernate;
import org.hibernate.Query;
@@ -57,23 +59,28 @@ public class ItemDaoImpl extends DaoImpl<IItem> implements IItemDao
return (List<IItem>) q.list();
}
+ public static APLCache<IItem> findItemByIdCache = new APLCache<>("ItemDaoImpl.findItemById");
+
@SuppressWarnings( "unused" )
@Override
public IItem findById(int id)
{
- String hql = "SELECT I, A FROM Item I, Author A WHERE I.IId = :itemId AND A.AId = I.author.AId";
- Query q = getCurrentSession().createQuery( hql );
- q.setParameter( "itemId", id );
- List res = q.list();
- if ( res != null && res.get( 0 ) == null )
- return null;
-
- IItem item = (Item) ( (Object[]) res.get( 0 ) )[0];
- // Hibernate.initialize( item.getShoppingCartLines() );
- // Hibernate.initialize( item.getOrderLines());
- return item;
+ return findItemByIdCache.computeIfAbsent(Thread.currentThread(), new Object[]{id}, () -> {
+ String hql = "SELECT I, A FROM Item I, Author A WHERE I.IId = :itemId AND A.AId = I.author.AId";
+ Query q = getCurrentSession().createQuery( hql );
+ q.setParameter( "itemId", id );
+ List res = q.list();
+ if ( res != null && res.get( 0 ) == null )
+ return null;
+
+ IItem item = (Item) ( (Object[]) res.get( 0 ) )[0];
+ // Hibernate.initialize( item.getShoppingCartLines() );
+ // Hibernate.initialize( item.getOrderLines());
+ return item;
+ }, 86400000);
}
+
@SuppressWarnings( "unchecked" )
@Override
public List<IItem> getPromotional()
@@ -137,25 +144,29 @@ public class ItemDaoImpl extends DaoImpl<IItem> implements IItemDao
return results;
}
+public static APLCache<List<IItem>> getNewProductsCache = new APLCache<>("ItemDaoImpl.getNewProducts");
+
@SuppressWarnings( "unchecked" )
@Override
// @Transactional( readOnly = true )
public List<IItem> getNewProducts(String category)
{
- Session session = getCurrentSession();
- Query query = session
- .createQuery( "SELECT I, A FROM Item as I, Author as A WHERE I.author.AId = A.AId AND I.ISubject = :category "
- + "ORDER BY I.IPubDate DESC, I.ITitle" );
- query.setString( "category", category );
- query.setMaxResults( 50 );
- ArrayList<IItem> newProducts = new ArrayList<IItem>();
-
- List<Object[]> res = query.list();
- for ( int i = 0; i < res.size(); i++ )
- {
- newProducts.add( (Item) ( res.get( i )[0] ) );
- }
- return newProducts;
+ return getNewProductsCache.computeIfAbsent(Thread.currentThread(), new Object[]{category}, () -> {
+ Session session = getCurrentSession();
+ Query query = session
+ .createQuery( "SELECT I, A FROM Item as I, Author as A WHERE I.author.AId = A.AId AND I.ISubject = :category "
+ + "ORDER BY I.IPubDate DESC, I.ITitle" );
+ query.setString( "category", category );
+ query.setMaxResults( 50 );
+ ArrayList<IItem> newProducts = new ArrayList<IItem>();
+
+ List<Object[]> res = query.list();
+ for ( int i = 0; i < res.size(); i++ )
+ {
+ newProducts.add( (Item) ( res.get( i )[0] ) );
+ }
+ return newProducts;
+ }, 86400000);
}
@SuppressWarnings( "unchecked" )
@@ -221,69 +232,81 @@ public class ItemDaoImpl extends DaoImpl<IItem> implements IItemDao
return new Item();
}
+public static APLCache<List<IItem>> findAllByAuthorCache = new APLCache<>("ItemDaoImpl.findAllByAuthor");
+
@SuppressWarnings( "unchecked" )
@Override
public List<IItem> findAllByAuthor(IAuthor author)
{
- String hql = "SELECT I FROM Item as I WHERE I.author = :author ORDER BY I.ITitle";
- Query query = getCurrentSession().createQuery( hql );
+ return findAllByAuthorCache.computeIfAbsent(Thread.currentThread(), new Object[]{author}, () -> {
+ String hql = "SELECT I FROM Item as I WHERE I.author = :author ORDER BY I.ITitle";
+ Query query = getCurrentSession().createQuery( hql );
- query.setParameter( "author", author );
- query.setMaxResults( 50 );
- // query.setCacheable( true );
+ query.setParameter( "author", author );
+ query.setMaxResults( 50 );
+ // query.setCacheable( true );
- List<IItem> res = query.list();
+ List<IItem> res = query.list();
- ArrayList<IItem> items = new ArrayList<IItem>();
- for ( IItem item : res )
- {
- Hibernate.initialize( item.getAuthor() );
- items.add( item );
- }
+ ArrayList<IItem> items = new ArrayList<IItem>();
+ for ( IItem item : res )
+ {
+ Hibernate.initialize( item.getAuthor() );
+ items.add( item );
+ }
- return items;
+ return items;
+ }, 86400000);
}
+public static APLCache<List<IItem>> findAllByTitleCache = new APLCache<>("ItemDaoImpl.findAllByTitle");
+
@SuppressWarnings( "unchecked" )
@Override
public List<IItem> findAllByTitle(String keyword)
{
- String hql = "SELECT I FROM Item as I, Author as A WHERE I.author.AId = A.AId AND substring(soundex(I.ITitle), 0, 4) = substring(soundex(:title), 0, 4) ORDER BY I.ITitle";
+ return findAllByTitleCache.computeIfAbsent(Thread.currentThread(), new Object[]{keyword}, () -> {
+ String hql = "SELECT I FROM Item as I, Author as A WHERE I.author.AId = A.AId AND substring(soundex(I.ITitle), 0, 4) = substring(soundex(:title), 0, 4) ORDER BY I.ITitle";
- Query query = getCurrentSession().createQuery( hql );
+ Query query = getCurrentSession().createQuery( hql );
- query.setParameter( "title", keyword );
- query.setMaxResults( 50 );
- // query.setCacheable( true );
+ query.setParameter( "title", keyword );
+ query.setMaxResults( 50 );
+ // query.setCacheable( true );
- List<IItem> res = query.list();
+ List<IItem> res = query.list();
- for ( IItem item : res )
- {
- Hibernate.initialize( item.getAuthor() );
- }
+ for ( IItem item : res )
+ {
+ Hibernate.initialize( item.getAuthor() );
+ }
- return res;
+ return res;
+ }, 86400000);
}
+public static APLCache<List<IItem>> findAllBySubjectCache = new APLCache<>("ItemDaoImpl.findAllBySubject");
+
@SuppressWarnings( "unchecked" )
@Override
public List<IItem> findAllBySubject(String keyword)
{
- String hql = "SELECT I FROM Item as I WHERE I.ISubject = :subject ORDER BY I.ITitle";
+ return findAllBySubjectCache.computeIfAbsent(Thread.currentThread(), new Object[]{keyword}, () -> {
+ String hql = "SELECT I FROM Item as I WHERE I.ISubject = :subject ORDER BY I.ITitle";
- Query query = getCurrentSession().createQuery( hql );
+ Query query = getCurrentSession().createQuery( hql );
- query.setParameter( "subject", keyword );
- query.setMaxResults( 50 );
- // query.setCacheable( true );
+ query.setParameter( "subject", keyword );
+ query.setMaxResults( 50 );
+ // query.setCacheable( true );
- List<IItem> res = query.list();
- for ( IItem item : res )
- {
- Hibernate.initialize( item.getAuthor() );
- }
+ List<IItem> res = query.list();
+ for ( IItem item : res )
+ {
+ Hibernate.initialize( item.getAuthor() );
+ }
- return res;
+ return res;
+ }, 86400000);
}
}
diff --git a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartDaoImpl.java b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartDaoImpl.java
index db1dfe5..e5e3dc9 100755
--- a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartDaoImpl.java
+++ b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartDaoImpl.java
@@ -12,6 +12,8 @@ package eu.cloudscale.showcase.db.dao.hibernate.impl;
import java.util.Date;
import java.util.List;
+import br.ufrgs.inf.prosoft.aplcache.caching.APLCache;
+
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;
@@ -36,29 +38,33 @@ public class ShoppingCartDaoImpl extends DaoImpl<IShoppingCart> implements IShop
super(sessionFactory);
}
+public static APLCache<IShoppingCart> findShoppingCartByIdCache = new APLCache<>("ShoppingCartDaoImpl.findShoppingCartById");
+
@SuppressWarnings( "rawtypes" )
@Override
// @Transactional(readOnly=true)
public IShoppingCart findById(Integer shoppingId)
{
- Session session = getCurrentSession();
- String hql = "SELECT SC FROM ShoppingCart as SC WHERE SC.scId = :scId";
-
- Query query = session.createQuery(hql);
- query.setParameter( "scId", shoppingId );
-
-
- List res = query.list();
-
- if( res.isEmpty() )
- {
-// System.out.println("results are empty! " + query.getQueryString());
- return null;
- }
-
- ShoppingCart sc = (ShoppingCart) res.get( 0 );
- Hibernate.initialize( sc.getShoppingCartLines() );
- return sc;
+ return findShoppingCartByIdCache.computeIfAbsent(Thread.currentThread(), new Object[]{shoppingId}, () -> {
+ Session session = getCurrentSession();
+ String hql = "SELECT SC FROM ShoppingCart as SC WHERE SC.scId = :scId";
+
+ Query query = session.createQuery(hql);
+ query.setParameter( "scId", shoppingId );
+
+
+ List res = query.list();
+
+ if( res.isEmpty() )
+ {
+ // System.out.println("results are empty! " + query.getQueryString());
+ return null;
+ }
+
+ ShoppingCart sc = (ShoppingCart) res.get( 0 );
+ Hibernate.initialize( sc.getShoppingCartLines() );
+ return sc;
+ }, 86400000);
}
@SuppressWarnings( "unchecked" )
diff --git a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartLineDaoImpl.java b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartLineDaoImpl.java
index 64cd271..6a7f817 100755
--- a/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartLineDaoImpl.java
+++ b/src/main/java/eu/cloudscale/showcase/db/dao/hibernate/impl/ShoppingCartLineDaoImpl.java
@@ -11,6 +11,8 @@ package eu.cloudscale.showcase.db.dao.hibernate.impl;
import java.util.List;
+import br.ufrgs.inf.prosoft.aplcache.caching.APLCache;
+
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
@@ -39,22 +41,25 @@ public class ShoppingCartLineDaoImpl extends DaoImpl<IShoppingCartLine> implemen
super( sessionFactory );
}
+ public static APLCache<IShoppingCartLine> getBySCandItemCache = new APLCache<>("ShoppingCartLineDaoImpl.getBySCandItem");
+
@SuppressWarnings( "unchecked" )
@Override
public IShoppingCartLine getBySCandItem(Integer shoppingId, int itemId)
{
- String hql1 = "SELECT SCL FROM ShoppingCartLine as SCL WHERE SCL.shoppingCart.scId = :scId AND SCL.item.IId = :itemId";
- Query q1 = getCurrentSession().createQuery( hql1 );
- q1.setMaxResults( 1 );
- q1.setParameter( "scId", shoppingId );
- q1.setParameter( "itemId", itemId);
-
- List<Object> res = q1.list();
- if( res.isEmpty() )
- return null;
-
- return (IShoppingCartLine) res.get( 0 );
-
+ return getBySCandItemCache.computeIfAbsent(Thread.currentThread(), new Object[]{shoppingId, itemId}, () -> {
+ String hql1 = "SELECT SCL FROM ShoppingCartLine as SCL WHERE SCL.shoppingCart.scId = :scId AND SCL.item.IId = :itemId";
+ Query q1 = getCurrentSession().createQuery( hql1 );
+ q1.setMaxResults( 1 );
+ q1.setParameter( "scId", shoppingId );
+ q1.setParameter( "itemId", itemId);
+
+ List<Object> res = q1.list();
+ if( res.isEmpty() )
+ return null;
+
+ return (IShoppingCartLine) res.get( 0 );
+ }, 86400000);
}
@Override
@@ -95,10 +100,10 @@ public class ShoppingCartLineDaoImpl extends DaoImpl<IShoppingCartLine> implemen
return res;
}
-
+
@Override
public IShoppingCartLine getObject()
{
- return new ShoppingCartLine();
+ return new ShoppingCartLine();
}
}
diff --git a/src/main/java/eu/cloudscale/showcase/db/services/AService.java b/src/main/java/eu/cloudscale/showcase/db/services/AService.java
index 46672f1..0a68826 100755
--- a/src/main/java/eu/cloudscale/showcase/db/services/AService.java
+++ b/src/main/java/eu/cloudscale/showcase/db/services/AService.java
@@ -16,6 +16,8 @@ import java.util.List;
import java.util.Random;
import java.util.Set;
+import br.ufrgs.inf.prosoft.aplcache.caching.APLCache;
+
import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;
@@ -495,10 +497,14 @@ public abstract class AService implements IService
return country1 == null;
}
+ public static APLCache<ICustomer> getUserByCache = new APLCache<>("AService.getUserBy");
+
@Override
public ICustomer getUserBy(String uname, String passwd)
{
- return customerDao.getUserBy( uname, passwd );
+ return getUserByCache.computeIfAbsent(Thread.currentThread(), new Object[]{uname, passwd}, () -> {
+ return customerDao.getUserBy( uname, passwd );
+ }, 86400000);
}
@Override
@@ -533,10 +539,14 @@ public abstract class AService implements IService
customerDao.shrani( customer );
}
+ public static APLCache<IShoppingCart> findShoppingCartByIdCache = new APLCache<>("AService.findShoppingCartById");
+
@Override
public IShoppingCart findShoppingCartById(Integer shoppingId)
{
- return shoppingCartDao.findById( shoppingId );
+ return findShoppingCartByIdCache.computeIfAbsent(Thread.currentThread(), new Object[]{shoppingId}, () -> {
+ return shoppingCartDao.findById( shoppingId );
+ }, 86400000);
}
@Override
@@ -552,22 +562,30 @@ public abstract class AService implements IService
return itemDao.getBestSellers( category );
}
+ public static APLCache<List<IItem>> searchByTitleCache = new APLCache<>("AService.searchByTitle");
+
@Override
// @Cacheable("search")
public List<IItem> searchByTitle(String keyword)
{
- List<IItem> items = itemDao.findAllByTitle( keyword );
-
- return items;
+ return searchByTitleCache.computeIfAbsent(Thread.currentThread(), new Object[]{keyword}, () -> {
+ List<IItem> items = itemDao.findAllByTitle( keyword );
+
+ return items;
+ }, 86400000);
}
+ public static APLCache<List<IItem>> searchBySubjectCache = new APLCache<>("AService.searchBySubject");
+
@Override
// @Cacheable("search")
public List<IItem> searchBySubject(String keyword)
{
- List<IItem> items = itemDao.findAllBySubject( keyword );
-
- return items;
+ return searchBySubjectCache.computeIfAbsent(Thread.currentThread(), new Object[]{keyword}, () -> {
+ List<IItem> items = itemDao.findAllBySubject( keyword );
+
+ return items;
+ }, 86400000);
}
@Override
@@ -581,10 +599,15 @@ public abstract class AService implements IService
{
return orderLineDao.findAllByOrder( order );
}
+
+ public static APLCache<IItem> findItemByIdCache = new APLCache<>("AService.findItemById");
+
@Override
public IItem findItemById(Integer itemId)
{
- return itemDao.findById( itemId );
+ return findItemByIdCache.computeIfAbsent(Thread.currentThread(), new Object[]{itemId}, () -> {
+ return itemDao.findById( itemId );
+ }, 86400000);
}
@Override
diff --git a/src/main/java/eu/cloudscale/showcase/servlets/AController.java b/src/main/java/eu/cloudscale/showcase/servlets/AController.java
index f5ef698..c59fe9c 100755
--- a/src/main/java/eu/cloudscale/showcase/servlets/AController.java
+++ b/src/main/java/eu/cloudscale/showcase/servlets/AController.java
@@ -12,6 +12,9 @@ package eu.cloudscale.showcase.servlets;
import java.io.IOException;
import java.util.Properties;
+import br.ufrgs.inf.prosoft.aplcache.caching.APLCache;
+import br.ufrgs.inf.prosoft.cache.GetterCache;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@@ -66,22 +69,26 @@ public abstract class AController
return url;
}
+ public static APLCache<String> getUrl1Cache = new APLCache<>("AController.getUrl1");
+
protected String getUrl1(Integer shoppingId, Integer customerId, String url1)
{
- String url = new String(url1);
- if( shoppingId != null )
- {
- url += "&SHOPPING_ID=" + shoppingId;
- }
-
- if( customerId != null )
- {
- url += "&C_ID=" + customerId;
- }
-
- return url;
+ return getUrl1Cache.computeIfAbsent(Thread.currentThread(), new Object[]{shoppingId, customerId, url1}, () -> {
+ String url = new String(url1);
+ if( shoppingId != null )
+ {
+ url += "&SHOPPING_ID=" + shoppingId;
+ }
+
+ if( customerId != null )
+ {
+ url += "&C_ID=" + customerId;
+ }
+
+ return url;
+ }, 86400000);
}
-
+
protected String getShoppingCartUrl(Integer shoppingId, Integer customerId)
{
return getUrl2( shoppingId, customerId, "/shopping-cart" );
@@ -96,10 +103,10 @@ public abstract class AController
{
return getUrl2( shoppingId, customerId, "/search" );
}
-
+
protected String getOrderInquiryUrl(Integer shoppingId, Integer customerId)
{
- return getUrl2( shoppingId, customerId, "/order-inquiry" );
+ return getUrl2( shoppingId, customerId, "/order-inquiry" );
}
protected void setupFrontend(Model model, Integer shoppingId, Integer customerId)
@@ -121,19 +128,23 @@ public abstract class AController
model.addAttribute( "jsResourceUrl", getApplicationProperties().get( "eu.cloudscale.files.url.js" ));
}
+ public static GetterCache<Properties> getApplicationPropertiesCache = new GetterCache<>("Acontroller.getApplicationProperties");
+
protected Properties getApplicationProperties()
{
- Resource resource = new ClassPathResource("/app.properties");
- Properties props = null;
- try
- {
- props = PropertiesLoaderUtils.loadProperties(resource);
- }
- catch ( IOException e )
- {
- e.printStackTrace();
- }
-
- return props;
+ return getApplicationPropertiesCache.computeIfAbsent(() -> {
+ Resource resource = new ClassPathResource("/app.properties");
+ Properties props = null;
+ try
+ {
+ props = PropertiesLoaderUtils.loadProperties(resource);
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ }
+
+ return props;
+ }, 60000);
}
}
diff --git a/src/main/java/eu/cloudscale/showcase/servlets/ShoppingCartController.java b/src/main/java/eu/cloudscale/showcase/servlets/ShoppingCartController.java
index bb54c7b..3372949 100755
--- a/src/main/java/eu/cloudscale/showcase/servlets/ShoppingCartController.java
+++ b/src/main/java/eu/cloudscale/showcase/servlets/ShoppingCartController.java
@@ -129,7 +129,6 @@ public class ShoppingCartController extends AController
return subtotal;
}
-
private String getCustomerRegistrationURL(Integer customerId, Integer shoppingId)
{
return getUrl2(shoppingId, customerId, "/customer-registration");