shopizer-memoizeit
Changes
docker-compose.yml 10(+2 -8)
pom.xml 4(+2 -2)
sm-core/pom.xml 52(+0 -52)
sm-core/src/main/java/com/salesmanager/core/business/repositories/catalog/product/relationship/ProductRelationshipRepositoryImpl.java 19(+18 -1)
sm-core/src/main/java/com/salesmanager/core/business/services/catalog/category/CategoryServiceImpl.java 10(+10 -0)
sm-core/src/main/java/com/salesmanager/core/business/services/catalog/product/relationship/ProductRelationshipServiceImpl.java 27(+26 -1)
sm-core/src/main/java/com/salesmanager/core/business/services/common/generic/SalesManagerEntityServiceImpl.java 6(+5 -1)
sm-core/src/main/java/com/salesmanager/core/business/services/content/ContentServiceImpl.java 8(+6 -2)
sm-core/src/main/java/com/salesmanager/core/business/services/customer/CustomerServiceImpl.java 16(+15 -1)
sm-core/src/main/java/com/salesmanager/core/business/services/reference/init/InitializationDatabaseImpl.java 7(+7 -0)
sm-core/src/main/java/com/salesmanager/core/business/services/reference/zone/ZoneServiceImpl.java 5(+5 -0)
sm-core/src/main/java/com/salesmanager/core/business/services/system/EmailServiceImpl.java 32(+20 -12)
sm-core/src/main/java/com/salesmanager/core/business/services/system/MerchantConfigurationServiceImpl.java 16(+11 -5)
sm-shop/pom.xml 52(+0 -52)
sm-shop/src/main/java/com/salesmanager/shop/store/controller/category/facade/CategoryFacadeImpl.java 12(+11 -1)
Details
docker-compose.yml 10(+2 -8)
diff --git a/docker-compose.yml b/docker-compose.yml
index 53f1e30..432e679 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -12,14 +12,8 @@ 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}
- - TRACER_SERIALISE_INTERNALS=false
- - TRACER_VERBOSE=true
- - TRACER_TRACES=/caching-approaches-comparison/applications/traces/shopizer
- - TRACER_IGNORED_PACKAGES=/caching-approaches-comparison/applications/uncached/shopizer/ignored
- - TRACER_WHITELIST=/caching-approaches-comparison/applications/uncached/shopizer/whitelist
- - TRACER_LOG=/caching-approaches-comparison/applications/output/shopizer-tracer.log
+ - CACHE_EVENTS=${CACHE_EVENTS:-/caching-approaches-comparison/applications/output/shopizer-memoizeit-cache}
+ - CACHE_REGISTER_SIZE=false
volumes:
- application:/application
- /root/.m2:/root/.m2
pom.xml 4(+2 -2)
diff --git a/pom.xml b/pom.xml
index 4a997aa..d7d7a5d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,8 +44,8 @@
<dependencies>
<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>
sm-core/pom.xml 52(+0 -52)
diff --git a/sm-core/pom.xml b/sm-core/pom.xml
index 4e8c652..282516c 100644
--- a/sm-core/pom.xml
+++ b/sm-core/pom.xml
@@ -204,56 +204,4 @@
</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>
- </plugins>
- </build>
-
-
-
</project>
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/modules/utils/GeoLocationImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/modules/utils/GeoLocationImpl.java
index 1be944f..c77fc6c 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/modules/utils/GeoLocationImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/modules/utils/GeoLocationImpl.java
@@ -10,6 +10,8 @@ import com.maxmind.geoip2.model.CityResponse;
import com.salesmanager.core.model.common.Address;
import com.salesmanager.core.modules.utils.GeoLocation;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+
/**
* Using Geolite2 City database
* http://dev.maxmind.com/geoip/geoip2/geolite2/#Databases
@@ -22,9 +24,13 @@ public class GeoLocationImpl implements GeoLocation {
private static final Logger LOGGER = LoggerFactory.getLogger( GeoLocationImpl.class );
+public static SingleCache<String, Address> getAddressCache = new SingleCache<>("GeoLocationImpl.getAddress");
+
@Override
public Address getAddress(String ipAddress) throws Exception {
-
+return getAddressCache.computeIfAbsent(ipAddress, () -> {
+ try {
+
if(reader==null) {
try {
java.io.InputStream inputFile = GeoLocationImpl.class.getClassLoader().getResourceAsStream("reference/GeoLite2-City.mmdb");
@@ -48,6 +54,10 @@ public class GeoLocationImpl implements GeoLocation {
return address;
+ } catch (Exception ex) {
+ return new Address();
+ }
+}, 1200000);
}
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/repositories/catalog/product/relationship/ProductRelationshipRepositoryImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/repositories/catalog/product/relationship/ProductRelationshipRepositoryImpl.java
index 1a943ff..e70dea7 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/repositories/catalog/product/relationship/ProductRelationshipRepositoryImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/repositories/catalog/product/relationship/ProductRelationshipRepositoryImpl.java
@@ -14,15 +14,21 @@ import com.salesmanager.core.model.catalog.product.relationship.ProductRelations
import com.salesmanager.core.model.merchant.MerchantStore;
import com.salesmanager.core.model.reference.language.Language;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
+
public class ProductRelationshipRepositoryImpl implements ProductRelationshipRepositoryCustom {
@PersistenceContext
private EntityManager em;
+
+public static SingleCache<Parameters, List<ProductRelationship>> getByTypeCache1 = new SingleCache<>("ProductRelationshipRepositoryImpl.getByType1");
@Override
public List<ProductRelationship> getByType(MerchantStore store, String type, Product product, Language language) {
+return getByTypeCache1.computeIfAbsent(new Parameters(store, type, product, language), () -> {
StringBuilder qs = new StringBuilder();
qs.append("select distinct pr from ProductRelationship as pr ");
@@ -54,11 +60,15 @@ public class ProductRelationshipRepositoryImpl implements ProductRelationshipRep
return relations;
+}, 1200000);
}
+public static SingleCache<Parameters, List<ProductRelationship>> getByTypeCache2 = new SingleCache<>("ProductRelationshipRepositoryImpl.getByType2");
@Override
public List<ProductRelationship> getByType(MerchantStore store, String type, Language language) {
+return getByTypeCache2.computeIfAbsent(new Parameters(store, type, language), () -> {
+
StringBuilder qs = new StringBuilder();
qs.append("select distinct pr from ProductRelationship as pr ");
@@ -100,6 +110,7 @@ public class ProductRelationshipRepositoryImpl implements ProductRelationshipRep
return relations;
+}, 1200000);
}
@@ -184,10 +195,11 @@ public class ProductRelationshipRepositoryImpl implements ProductRelationshipRep
}
-
+ public static SingleCache<Parameters, List<ProductRelationship>> getByTypeCache3 = new SingleCache<>("ProductRelationshipRepositoryImpl.getByType3");
@Override
public List<ProductRelationship> getByType(MerchantStore store, String type) {
+return getByTypeCache3.computeIfAbsent(new Parameters(store, type), () -> {
StringBuilder qs = new StringBuilder();
qs.append("select distinct pr from ProductRelationship as pr ");
qs.append("left join fetch pr.product p ");
@@ -213,6 +225,7 @@ public class ProductRelationshipRepositoryImpl implements ProductRelationshipRep
return relations;
+}, 1200000);
}
@@ -249,8 +262,11 @@ public class ProductRelationshipRepositoryImpl implements ProductRelationshipRep
}
+
+ public static SingleCache<Parameters, List<ProductRelationship>> getByTypeCache4 = new SingleCache<>("ProductRelationshipRepositoryImpl.getByType4");
@Override
public List<ProductRelationship> getByType(MerchantStore store, String type, Product product) {
+return getByTypeCache4.computeIfAbsent(new Parameters(store, type, product), () -> {
StringBuilder qs = new StringBuilder();
@@ -293,6 +309,7 @@ public class ProductRelationshipRepositoryImpl implements ProductRelationshipRep
return relations;
+}, 1200000);
}
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/services/catalog/category/CategoryServiceImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/services/catalog/category/CategoryServiceImpl.java
index 7dd7467..1ec5214 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/services/catalog/category/CategoryServiceImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/services/catalog/category/CategoryServiceImpl.java
@@ -23,6 +23,9 @@ import com.salesmanager.core.model.catalog.product.Product;
import com.salesmanager.core.model.merchant.MerchantStore;
import com.salesmanager.core.model.reference.language.Language;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
+
@Service("categoryService")
public class CategoryServiceImpl extends SalesManagerEntityServiceImpl<Long, Category> implements CategoryService {
@@ -352,14 +355,21 @@ public class CategoryServiceImpl extends SalesManagerEntityServiceImpl<Long, Cat
}
+public static SingleCache<Parameters, List<Category>> listByDepthCache1 = new SingleCache<>("CategoryServiceImpl.listByDepth1");
+
@Override
public List<Category> listByDepth(MerchantStore store, int depth) {
+return listByDepthCache1.computeIfAbsent(new Parameters(store, depth), () -> {
return categoryRepository.findByDepth(store.getId(), depth);
+}, 1200000);
}
+public static SingleCache<Parameters, List<Category>> listByDepthCache2 = new SingleCache<>("CategoryServiceImpl.listByDepth2");
@Override
public List<Category> listByDepth(MerchantStore store, int depth, Language language) {
+return listByDepthCache2.computeIfAbsent(new Parameters(store, depth, language), () -> {
return categoryRepository.findByDepth(store.getId(), depth, language.getId());
+}, 1200000);
}
@Override
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/services/catalog/product/relationship/ProductRelationshipServiceImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/services/catalog/product/relationship/ProductRelationshipServiceImpl.java
index 6affbce..b92f9e0 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/services/catalog/product/relationship/ProductRelationshipServiceImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/services/catalog/product/relationship/ProductRelationshipServiceImpl.java
@@ -15,6 +15,9 @@ import com.salesmanager.core.model.catalog.product.relationship.ProductRelations
import com.salesmanager.core.model.merchant.MerchantStore;
import com.salesmanager.core.model.reference.language.Language;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
+
@Service("productRelationshipService")
public class ProductRelationshipServiceImpl extends
SalesManagerEntityServiceImpl<Long, ProductRelationship> implements
@@ -100,46 +103,68 @@ public class ProductRelationshipServiceImpl extends
}
-
+public static SingleCache<Parameters, List<ProductRelationship>> getByTypeCache1 = new SingleCache<>("ProductRelationshipServiceImpl.getByType1");
+
@Override
public List<ProductRelationship> getByType(MerchantStore store, Product product, ProductRelationshipType type, Language language) throws ServiceException {
+return getByTypeCache1.computeIfAbsent(new Parameters(store, product, type, language), () -> {
return productRelationshipRepository.getByType(store, type.name(), product, language);
+}, 1200000);
}
+public static SingleCache<Parameters, List<ProductRelationship>> getByTypeCache2 = new SingleCache<>("ProductRelationshipServiceImpl.getByType2");
+
@Override
public List<ProductRelationship> getByType(MerchantStore store, ProductRelationshipType type, Language language) throws ServiceException {
+return getByTypeCache2.computeIfAbsent(new Parameters(store, type, language), () -> {
return productRelationshipRepository.getByType(store, type.name(), language);
+}, 1200000);
}
+public static SingleCache<Parameters, List<ProductRelationship>> getByTypeCache3 = new SingleCache<>("ProductRelationshipServiceImpl.getByType3");
@Override
public List<ProductRelationship> getByType(MerchantStore store, ProductRelationshipType type) throws ServiceException {
+return getByTypeCache3.computeIfAbsent(new Parameters(store, type), () -> {
return productRelationshipRepository.getByType(store, type.name());
+}, 1200000);
}
+
+public static SingleCache<Parameters, List<ProductRelationship>> getByGroupCache1 = new SingleCache<>("ProductRelationshipServiceImpl.getByGroup1");
@Override
public List<ProductRelationship> getByGroup(MerchantStore store, String groupName) throws ServiceException {
+return getByGroupCache1.computeIfAbsent(new Parameters(store, groupName), () -> {
return productRelationshipRepository.getByType(store, groupName);
+}, 1200000);
}
+ public static SingleCache<Parameters, List<ProductRelationship>> getByGroupCache2 = new SingleCache<>("ProductRelationshipServiceImpl.getByGroup2");
+
@Override
public List<ProductRelationship> getByGroup(MerchantStore store, String groupName, Language language) throws ServiceException {
+return getByGroupCache2.computeIfAbsent(new Parameters(store, groupName, language), () -> {
return productRelationshipRepository.getByType(store, groupName, language);
+}, 1200000);
}
+
+ public static SingleCache<Parameters, List<ProductRelationship>> getByTypeCache4 = new SingleCache<>("ProductRelationshipServiceImpl.getByType4");
@Override
public List<ProductRelationship> getByType(MerchantStore store, Product product, ProductRelationshipType type) throws ServiceException {
+return getByTypeCache4.computeIfAbsent(new Parameters(store, product, type), () -> {
return productRelationshipRepository.getByType(store, type.name(), product);
+}, 1200000);
}
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/services/common/generic/SalesManagerEntityServiceImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/services/common/generic/SalesManagerEntityServiceImpl.java
index 3ff68ee..df80a33 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/services/common/generic/SalesManagerEntityServiceImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/services/common/generic/SalesManagerEntityServiceImpl.java
@@ -9,6 +9,8 @@ import org.springframework.data.jpa.repository.JpaRepository;
import com.salesmanager.core.business.exception.ServiceException;
import com.salesmanager.core.model.generic.SalesManagerEntity;
+import br.ufrgs.inf.prosoft.cache.GetterCache;
+
/**
* @param <T> entity type
*/
@@ -71,9 +73,11 @@ public abstract class SalesManagerEntityServiceImpl<K extends Serializable & Com
return repository.findAll();
}
-
+public static GetterCache<Long> countCache = new GetterCache<>("SalesManagerEntityServiceImpl.count");
public Long count() {
+return countCache.computeIfAbsent(() -> {
return repository.count();
+}, 1200000);
}
}
\ No newline at end of file
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/services/content/ContentServiceImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/services/content/ContentServiceImpl.java
index 25f85e5..755e08a 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/services/content/ContentServiceImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/services/content/ContentServiceImpl.java
@@ -22,6 +22,8 @@ import com.salesmanager.core.model.content.OutputContentFile;
import com.salesmanager.core.model.merchant.MerchantStore;
import com.salesmanager.core.model.reference.language.Language;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
@Service( "contentService" )
@@ -85,13 +87,15 @@ public class ContentServiceImpl
return contentRepository.findByTypes( contentType, store.getId(), language.getId() );
}
+public static SingleCache<Parameters, List<ContentDescription>> listNameByTypeCache = new SingleCache<>("ContentServiceImpl.listNameByType");
+
@Override
public List<ContentDescription> listNameByType( List<ContentType> contentType, MerchantStore store, Language language )
throws ServiceException
{
-
-
+ return listNameByTypeCache.computeIfAbsent(new Parameters(contentType, store, language), () -> {
return contentRepository.listNameByType(contentType, store, language);
+ }, 1200000);
}
@Override
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/services/customer/CustomerServiceImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/services/customer/CustomerServiceImpl.java
index ee6eb94..71c6620 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/services/customer/CustomerServiceImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/services/customer/CustomerServiceImpl.java
@@ -20,6 +20,8 @@ import com.salesmanager.core.model.customer.attribute.CustomerAttribute;
import com.salesmanager.core.model.merchant.MerchantStore;
import com.salesmanager.core.modules.utils.GeoLocation;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
@Service("customerService")
@@ -52,14 +54,21 @@ public class CustomerServiceImpl extends SalesManagerEntityServiceImpl<Long, Cus
return customerRepository.findOne(id);
}
+public static SingleCache<String, Customer> getByNickCache1 = new SingleCache<>("CustomerServiceImpl.getByNick1");
+
@Override
public Customer getByNick(String nick) {
+return getByNickCache1.computeIfAbsent(nick, () -> {
return customerRepository.findByNick(nick);
+}, 1200000);
}
+public static SingleCache<Parameters, Customer> getByNickCache2 = new SingleCache<>("CustomerServiceImpl.getByNick2");
@Override
public Customer getByNick(String nick, int storeId) {
+return getByNickCache2.computeIfAbsent(new Parameters(nick, storeId), () -> {
return customerRepository.findByNick(nick, storeId);
+}, 1200000);
}
@Override
@@ -72,14 +81,19 @@ public class CustomerServiceImpl extends SalesManagerEntityServiceImpl<Long, Cus
return customerRepository.listByStore(store,criteria);
}
+public static SingleCache<Parameters, Address> getCustomerAddressCache = new SingleCache<>("CustomerServiceImpl.getCustomerAddress");
+
@Override
public Address getCustomerAddress(MerchantStore store, String ipAddress) throws ServiceException {
+return getCustomerAddressCache.computeIfAbsent(new Parameters(store, ipAddress), () -> {
try {
return geoLocation.getAddress(ipAddress);
} catch(Exception e) {
- throw new ServiceException(e);
+ // throw new ServiceException(e);
+ return new Address();
}
+}, 1200000);
}
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/services/reference/init/InitializationDatabaseImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/services/reference/init/InitializationDatabaseImpl.java
index 97e6a4d..dd7ec76 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/services/reference/init/InitializationDatabaseImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/services/reference/init/InitializationDatabaseImpl.java
@@ -37,6 +37,8 @@ import com.salesmanager.core.model.reference.zone.ZoneDescription;
import com.salesmanager.core.model.system.IntegrationModule;
import com.salesmanager.core.model.tax.taxclass.TaxClass;
+import br.ufrgs.inf.prosoft.cache.GetterCache;
+
@Service("initializationDatabase")
public class InitializationDatabaseImpl implements InitializationDatabase {
@@ -78,8 +80,13 @@ public class InitializationDatabaseImpl implements InitializationDatabase {
private String name;
+
+public static GetterCache<Boolean> isEmptyCache = new GetterCache<>("InitializationDatabaseImpl.isEmpty");
+
public boolean isEmpty() {
+return isEmptyCache.computeIfAbsent(() -> {
return languageService.count() == 0;
+}, 1200000);
}
@Transactional
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/services/reference/zone/ZoneServiceImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/services/reference/zone/ZoneServiceImpl.java
index 9a94591..0f38ada 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/services/reference/zone/ZoneServiceImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/services/reference/zone/ZoneServiceImpl.java
@@ -21,6 +21,8 @@ import com.salesmanager.core.model.reference.language.Language;
import com.salesmanager.core.model.reference.zone.Zone;
import com.salesmanager.core.model.reference.zone.ZoneDescription;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+
@Service("zoneService")
public class ZoneServiceImpl extends SalesManagerEntityServiceImpl<Long, Zone> implements
ZoneService {
@@ -40,9 +42,12 @@ public class ZoneServiceImpl extends SalesManagerEntityServiceImpl<Long, Zone> i
this.zoneRepository = zoneRepository;
}
+public static SingleCache<String, Zone> getByCodeCache = new SingleCache<>("ZoneServiceImpl.getByCode");
@Override
public Zone getByCode(String code) {
+return getByCodeCache.computeIfAbsent(code, () -> {
return zoneRepository.findByCode(code);
+}, 1200000);
}
@Override
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/services/system/EmailServiceImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/services/system/EmailServiceImpl.java
index c5eaafe..7a59c2f 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/services/system/EmailServiceImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/services/system/EmailServiceImpl.java
@@ -13,6 +13,8 @@ import com.salesmanager.core.business.modules.email.HtmlEmailSender;
import com.salesmanager.core.model.merchant.MerchantStore;
import com.salesmanager.core.model.system.MerchantConfiguration;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+
@Service("emailService")
public class EmailServiceImpl implements EmailService {
@@ -26,27 +28,33 @@ public class EmailServiceImpl implements EmailService {
public void sendHtmlEmail(MerchantStore store, Email email) throws ServiceException, Exception {
EmailConfig emailConfig = getEmailConfiguration(store);
-
+
sender.setEmailConfig(emailConfig);
sender.send(email);
- }
-
+ }
+
+public static SingleCache<MerchantStore, EmailConfig> getEmailConfigurationCache = new SingleCache<>("EmailServiceImpl.getEmailConfiguration");
+
@Override
- public EmailConfig getEmailConfiguration(MerchantStore store) throws ServiceException {
+ public EmailConfig getEmailConfiguration(MerchantStore store) {
+
+return getEmailConfigurationCache.computeIfAbsent(store, () -> {
- MerchantConfiguration configuration = merchantConfigurationService.getMerchantConfiguration(Constants.EMAIL_CONFIG, store);
EmailConfig emailConfig = null;
- if(configuration!=null) {
- String value = configuration.getValue();
-
- ObjectMapper mapper = new ObjectMapper();
- try {
+ try {
+ MerchantConfiguration configuration = merchantConfigurationService.getMerchantConfiguration(Constants.EMAIL_CONFIG, store);
+ if(configuration!=null) {
+ String value = configuration.getValue();
+
+ ObjectMapper mapper = new ObjectMapper();
emailConfig = mapper.readValue(value, EmailConfig.class);
- } catch(Exception e) {
- throw new ServiceException("Cannot parse json string " + value);
}
+ } catch(ServiceException ex) {
+ } catch(Exception e) {
+ // throw new ServiceException("Cannot parse json string " + value);
}
return emailConfig;
+}, 1200000);
}
diff --git a/sm-core/src/main/java/com/salesmanager/core/business/services/system/MerchantConfigurationServiceImpl.java b/sm-core/src/main/java/com/salesmanager/core/business/services/system/MerchantConfigurationServiceImpl.java
index 50e0b52..cd99860 100644
--- a/sm-core/src/main/java/com/salesmanager/core/business/services/system/MerchantConfigurationServiceImpl.java
+++ b/sm-core/src/main/java/com/salesmanager/core/business/services/system/MerchantConfigurationServiceImpl.java
@@ -16,6 +16,8 @@ import com.salesmanager.core.model.system.MerchantConfig;
import com.salesmanager.core.model.system.MerchantConfiguration;
import com.salesmanager.core.model.system.MerchantConfigurationType;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+
@Service("merchantConfigurationService")
public class MerchantConfigurationServiceImpl extends
SalesManagerEntityServiceImpl<Long, MerchantConfiguration> implements
@@ -68,23 +70,27 @@ public class MerchantConfigurationServiceImpl extends
}
}
+public static SingleCache<MerchantStore, MerchantConfig> getMerchantConfigCache = new SingleCache<>("MerchantConfigurationServiceImpl.getMerchantConfig");
+
@Override
- public MerchantConfig getMerchantConfig(MerchantStore store) throws ServiceException {
+ public MerchantConfig getMerchantConfig(MerchantStore store) {
+return getMerchantConfigCache.computeIfAbsent(store, () -> {
+ MerchantConfig config = null;
+ try {
MerchantConfiguration configuration = merchantConfigurationRepository.findByMerchantStoreAndKey(store.getId(), MerchantConfigurationType.CONFIG.name());
- MerchantConfig config = null;
if(configuration!=null) {
String value = configuration.getValue();
ObjectMapper mapper = new ObjectMapper();
- try {
config = mapper.readValue(value, MerchantConfig.class);
+ }
} catch(Exception e) {
- throw new ServiceException("Cannot parse json string " + value);
+ // throw new ServiceException("Cannot parse json string " + value);
}
- }
return config;
+}, 1200000);
}
sm-shop/pom.xml 52(+0 -52)
diff --git a/sm-shop/pom.xml b/sm-shop/pom.xml
index 9eb8ac0..d9321d1 100644
--- a/sm-shop/pom.xml
+++ b/sm-shop/pom.xml
@@ -159,57 +159,5 @@
</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>
- </plugins>
- </build>
-
</project>
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/filter/StoreFilter.java b/sm-shop/src/main/java/com/salesmanager/shop/filter/StoreFilter.java
index a26158d..0a12202 100644
--- a/sm-shop/src/main/java/com/salesmanager/shop/filter/StoreFilter.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/filter/StoreFilter.java
@@ -51,6 +51,9 @@ import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
+
/**
* Servlet Filter implementation class StoreFilter
*/
@@ -705,9 +708,12 @@ public class StoreFilter extends HandlerInterceptorAdapter {
}
*/
+public static SingleCache<Parameters, Map<String, List<ContentDescription>>> getContentPagesNamesCache = new SingleCache<>("StoreFilter.getContentPagesNames");
+
private Map<String, List<ContentDescription>> getContentPagesNames(MerchantStore store, Language language) throws Exception {
-
+return getContentPagesNamesCache.computeIfAbsent(new Parameters(store, language), () -> {
+ try {
Map<String, List<ContentDescription>> contents = new ConcurrentHashMap<String, List<ContentDescription>>();
//Get boxes and sections from the database
@@ -749,11 +755,17 @@ public class StoreFilter extends HandlerInterceptorAdapter {
}
}
return contents;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+}, 1200000);
}
+
+public static SingleCache<Parameters, Map<String, List<Content>>> getContentCache = new SingleCache<>("StoreFilter.getContentCache");
private Map<String, List<Content>> getContent(MerchantStore store, Language language) throws Exception {
-
-
+return getContentCache.computeIfAbsent(new Parameters(store, language), () -> {
+try {
Map<String, List<Content>> contents = new ConcurrentHashMap<String, List<Content>>();
//Get boxes and sections from the database
@@ -798,6 +810,10 @@ public class StoreFilter extends HandlerInterceptorAdapter {
}
}
return contents;
+} catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+}, 1200000);
}
/**
@@ -880,9 +896,12 @@ public class StoreFilter extends HandlerInterceptorAdapter {
return objects;
}
+public static SingleCache<MerchantStore, Map<String, Object>> getConfigurationsCache = new SingleCache<>("StoreFilter.getConfigurations");
+
@SuppressWarnings("unused")
private Map<String,Object> getConfigurations(MerchantStore store) {
+return getConfigurationsCache.computeIfAbsent(store, () -> {
Map<String,Object> configs = new HashMap<String,Object>();
try {
@@ -920,6 +939,7 @@ public class StoreFilter extends HandlerInterceptorAdapter {
}
return configs;
+}, 1200000);
}
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/store/controller/category/facade/CategoryFacadeImpl.java b/sm-shop/src/main/java/com/salesmanager/shop/store/controller/category/facade/CategoryFacadeImpl.java
index 4296375..ffcbb4e 100644
--- a/sm-shop/src/main/java/com/salesmanager/shop/store/controller/category/facade/CategoryFacadeImpl.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/store/controller/category/facade/CategoryFacadeImpl.java
@@ -17,6 +17,8 @@ import javax.inject.Inject;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
@Service( value = "categoryFacade" )
public class CategoryFacadeImpl implements CategoryFacade {
@@ -27,10 +29,14 @@ public class CategoryFacadeImpl implements CategoryFacade {
@Inject
private LanguageService languageService;
+public static SingleCache<Parameters, List<ReadableCategory>> getCategoryHierarchyCache = new SingleCache<>("CategoryFacadeImpl.getCategoryHierarchy");
+
+
@Override
public List<ReadableCategory> getCategoryHierarchy(MerchantStore store,
int depth, Language language) throws Exception {
-
+return getCategoryHierarchyCache.computeIfAbsent(new Parameters(store, depth, language), () -> {
+ try {
List<Category> categories = categoryService.listByDepth(store, depth, language);
List<ReadableCategory> returnValues = new ArrayList<ReadableCategory>();
@@ -78,6 +84,10 @@ public class CategoryFacadeImpl implements CategoryFacade {
} );
return returnValues;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+}, 1200000);
}
@Override
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/store/controller/customer/facade/CustomerFacadeImpl.java b/sm-shop/src/main/java/com/salesmanager/shop/store/controller/customer/facade/CustomerFacadeImpl.java
index 3ccd3ea..41ae4ec 100644
--- a/sm-shop/src/main/java/com/salesmanager/shop/store/controller/customer/facade/CustomerFacadeImpl.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/store/controller/customer/facade/CustomerFacadeImpl.java
@@ -54,6 +54,9 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
+
//import com.salesmanager.core.business.customer.CustomerRegistrationException;
//import com.salesmanager.core.business.customer.exception.CustomerNotFoundException;
@@ -234,13 +237,15 @@ public class CustomerFacadeImpl implements CustomerFacade
}
-
+public static SingleCache<Parameters, Customer> getCustomerByUserNameCache = new SingleCache<>("CustomerFacadeImpl.getCustomerByUserName");
@Override
public Customer getCustomerByUserName(String userName, MerchantStore store)
throws Exception {
+return getCustomerByUserNameCache.computeIfAbsent(new Parameters(userName, store), () -> {
return customerService.getByNick( userName, store.getId() );
+}, 1200000);
}
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/store/controller/error/ErrorController.java b/sm-shop/src/main/java/com/salesmanager/shop/store/controller/error/ErrorController.java
index cdbd5c3..c0e6513 100644
--- a/sm-shop/src/main/java/com/salesmanager/shop/store/controller/error/ErrorController.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/store/controller/error/ErrorController.java
@@ -12,6 +12,9 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+
+
@ControllerAdvice
public class ErrorController {
@@ -45,9 +48,12 @@ public class ErrorController {
}
+public static SingleCache<Exception, ModelAndView> handleRuntimeExceptionCache = new SingleCache<>("ErrorController.handleRuntimeException");
+
@ExceptionHandler(RuntimeException.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView handleRuntimeException(Exception ex) {
+return handleRuntimeExceptionCache.computeIfAbsent(ex, () -> {
LOGGER.error("Error page controller",ex);
@@ -62,6 +68,7 @@ public class ErrorController {
return model;
+}, 1200000);
}
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/utils/BeanUtils.java b/sm-shop/src/main/java/com/salesmanager/shop/utils/BeanUtils.java
index 1146dfb..8b2121b 100644
--- a/sm-shop/src/main/java/com/salesmanager/shop/utils/BeanUtils.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/utils/BeanUtils.java
@@ -7,6 +7,9 @@ import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
+
public class BeanUtils
{
private BeanUtils(){
@@ -16,50 +19,72 @@ public class BeanUtils
public static BeanUtils newInstance(){
return new BeanUtils();
}
+
+public static SingleCache<Parameters, Object> getPropertyValueCache = new SingleCache<>("BeanUtils.getPropertyValue");
@SuppressWarnings( "nls" )
public Object getPropertyValue( Object bean, String property )
- throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
+ // throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
+ return getPropertyValueCache.computeIfAbsent(new Parameters(bean, property), () -> {
- if (bean == null) {
- throw new IllegalArgumentException("No bean specified");
- }
- if(property == null){
-
- throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
- }
- Class<?> beanClass = bean.getClass();
- PropertyDescriptor propertyDescriptor = getPropertyDescriptor( beanClass, property );
- if ( propertyDescriptor == null )
- {
- throw new IllegalArgumentException( "No such property " + property + " for " + beanClass + " exists" );
- }
+ if (bean == null) {
+ // throw new IllegalArgumentException("No bean specified");
+ throw new RuntimeException("No bean specified");
+ }
+ if(property == null){
+
+ // throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
+ throw new RuntimeException("No name specified for bean class '" + bean.getClass() + "'");
+ }
+try {
- Method readMethod = propertyDescriptor.getReadMethod();
- if ( readMethod == null )
- {
- throw new IllegalStateException( "No getter available for property " + property + " on " + beanClass );
- }
- return readMethod.invoke( bean );
+ Class<?> beanClass = bean.getClass();
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor( beanClass, property );
+ if ( propertyDescriptor == null )
+ {
+ // throw new IllegalArgumentException( "No such property " + property + " for " + beanClass + " exists" );
+ throw new RuntimeException( "No such property " + property + " for " + beanClass + " exists" );
+ }
+
+ Method readMethod = propertyDescriptor.getReadMethod();
+ if ( readMethod == null )
+ {
+ // throw new IllegalStateException( "No getter available for property " + property + " on " + beanClass );
+ throw new RuntimeException( "No getter available for property " + property + " on " + beanClass );
+ }
+ return readMethod.invoke( bean );
+} catch (InvocationTargetException | IllegalAccessException ex) {
+ throw new RuntimeException(ex);
+}
+ }, 1200000);
}
+public static SingleCache<Parameters, PropertyDescriptor> getPropertyDescriptorCache = new SingleCache<>("BeanUtils.getPropertyDescriptor");
+
private PropertyDescriptor getPropertyDescriptor( Class<?> beanClass, String propertyname )
- throws IntrospectionException
+ // throws IntrospectionException
{
- BeanInfo beanInfo = Introspector.getBeanInfo( beanClass );
- PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
- PropertyDescriptor propertyDescriptor = null;
- for ( int i = 0; i < propertyDescriptors.length; i++ )
- {
- PropertyDescriptor currentPropertyDescriptor = propertyDescriptors[i];
- if ( currentPropertyDescriptor.getName().equals( propertyname ) )
+ return getPropertyDescriptorCache.computeIfAbsent(new Parameters(beanClass, propertyname), () -> {
+ try {
+
+ BeanInfo beanInfo = Introspector.getBeanInfo( beanClass );
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ PropertyDescriptor propertyDescriptor = null;
+ for ( int i = 0; i < propertyDescriptors.length; i++ )
{
- propertyDescriptor = currentPropertyDescriptor;
- }
+ PropertyDescriptor currentPropertyDescriptor = propertyDescriptors[i];
+ if ( currentPropertyDescriptor.getName().equals( propertyname ) )
+ {
+ propertyDescriptor = currentPropertyDescriptor;
+ }
- }
- return propertyDescriptor;
+ }
+ return propertyDescriptor;
+ } catch (IntrospectionException ex) {
+ throw new RuntimeException(ex);
+ }
+ }, 1200000);
}
}
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/utils/EmailUtils.java b/sm-shop/src/main/java/com/salesmanager/shop/utils/EmailUtils.java
index a1ac85a..95b2b63 100644
--- a/sm-shop/src/main/java/com/salesmanager/shop/utils/EmailUtils.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/utils/EmailUtils.java
@@ -12,6 +12,8 @@ import org.springframework.stereotype.Component;
import com.salesmanager.core.model.merchant.MerchantStore;
import com.salesmanager.shop.constants.Constants;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
@Component
public class EmailUtils {
@@ -27,6 +29,8 @@ public class EmailUtils {
@Qualifier("img")
private ImageFilePath imageUtils;
+public static SingleCache<Parameters, Map<String, String>> createEmailObjectsMapCache = new SingleCache<>("EmailUtils.createEmailObjectsMap");
+
/**
* Builds generic html email information
* @param store
@@ -36,6 +40,7 @@ public class EmailUtils {
*/
public Map<String, String> createEmailObjectsMap(String contextPath, MerchantStore store, LabelUtils messages, Locale locale){
+return createEmailObjectsMapCache.computeIfAbsent(new Parameters(contextPath, store, messages, locale), () -> {
Map<String, String> templateTokens = new HashMap<String, String>();
String[] adminNameArg = {store.getStorename()};
@@ -59,6 +64,7 @@ public class EmailUtils {
}
return templateTokens;
+}, 1200000);
}
}
diff --git a/sm-shop/src/main/java/com/salesmanager/shop/utils/FieldMatchValidator.java b/sm-shop/src/main/java/com/salesmanager/shop/utils/FieldMatchValidator.java
index 9a4d74d..73c01e5 100644
--- a/sm-shop/src/main/java/com/salesmanager/shop/utils/FieldMatchValidator.java
+++ b/sm-shop/src/main/java/com/salesmanager/shop/utils/FieldMatchValidator.java
@@ -7,6 +7,8 @@ import org.slf4j.LoggerFactory;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
+import br.ufrgs.inf.prosoft.cache.SingleCache;
+import br.ufrgs.inf.prosoft.cache.Parameters;
public class FieldMatchValidator implements ConstraintValidator<FieldMatch, Object>
{
@@ -24,10 +26,14 @@ public class FieldMatchValidator implements ConstraintValidator<FieldMatch, Obje
this.beanUtils=BeanUtils.newInstance();
}
+
+public static SingleCache<Parameters, Boolean> isValidCache = new SingleCache<>("FieldMatchValidator.isValid");
+
@SuppressWarnings( "nls" )
@Override
public boolean isValid(final Object value, final ConstraintValidatorContext context)
{
+return isValidCache.computeIfAbsent(new Parameters(value, context), () -> {
try
{
final Object firstObj = this.beanUtils.getPropertyValue(value, this.firstFieldName);
@@ -40,6 +46,7 @@ public class FieldMatchValidator implements ConstraintValidator<FieldMatch, Obje
return false;
}
+}, 1200000);
}
}