com.parthparekh.service.cache
Class ProductCacheService

java.lang.Object
  extended by com.parthparekh.service.cache.ProductCacheService
All Implemented Interfaces:
ProductService

@Service
@Transactional
@Qualifier(value="cache")
public class ProductCacheService
extends java.lang.Object
implements ProductService

Caching layer for Product web service for create/update - this service will first change the product in mongoDb (by calling productServiceImpl) and then update the cache for get - this service will first check the cache; if the value is not found, it will query the mongoDb (by calling productSericeImpl)


Field Summary
private static java.lang.String ALL_PRODUCTS_CACHE_KEY
           
private  Cache cache
           
private static org.slf4j.Logger logger
           
private  ProductService productService
           
private  ProductServiceUtils productServiceUtils
           
 
Constructor Summary
ProductCacheService()
           
 
Method Summary
 Product createProduct(Product product)
          creates a product with name, description and price
 java.util.List<Product> getAll()
          retrieves all the available products
 Product getProduct(java.lang.String id)
          retrieves product information from id
private  void saveProductInCache(Product product)
           
 Product updateProduct(java.lang.String id, Product product)
          update product information
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final org.slf4j.Logger logger

ALL_PRODUCTS_CACHE_KEY

private static final java.lang.String ALL_PRODUCTS_CACHE_KEY
See Also:
Constant Field Values

cache

@Autowired
@Qualifier(value="defaultCache")
private Cache cache

productService

@Autowired
@Qualifier(value="default")
private ProductService productService

productServiceUtils

@Autowired
private ProductServiceUtils productServiceUtils
Constructor Detail

ProductCacheService

public ProductCacheService()
Method Detail

createProduct

public Product createProduct(Product product)
Description copied from interface: ProductService
creates a product with name, description and price

Specified by:
createProduct in interface ProductService
Parameters:
product - - product containing name, description, status and price
Returns:
returns the product persisted in db

getProduct

public Product getProduct(java.lang.String id)
Description copied from interface: ProductService
retrieves product information from id

Specified by:
getProduct in interface ProductService
Parameters:
id - - product id
Returns:
returns the product from db

getAll

public java.util.List<Product> getAll()
Description copied from interface: ProductService
retrieves all the available products

Specified by:
getAll in interface ProductService
Returns:
returns all the products stored in db

updateProduct

public Product updateProduct(java.lang.String id,
                             Product product)
Description copied from interface: ProductService
update product information

Specified by:
updateProduct in interface ProductService
Parameters:
id - - product identifier to update
product - - product object containing updated fields
Returns:
returns the updated product

saveProductInCache

private void saveProductInCache(Product product)