Update CustomerDataService.java
This commit is contained in:
		
							parent
							
								
									90e8b48955
								
							
						
					
					
						commit
						e71147dd35
					
				| @ -10,84 +10,84 @@ import org.springframework.stereotype.Component; | ||||
| @CacheConfig("addressDemo") | ||||
| public class CustomerDataService { | ||||
| 
 | ||||
| 	/** The cache manager. */ | ||||
| 	@Autowired | ||||
| 	CacheManager cacheManager; | ||||
|     /** The cache manager. */ | ||||
|     @Autowired | ||||
|     CacheManager cacheManager; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The method returns the customer's address, | ||||
| 	   only it doesn't find it the cache- addresses and directory. | ||||
| 	 * | ||||
| 	 * @param customer the customer | ||||
| 	 * @return the address | ||||
| 	 */ | ||||
|     /** | ||||
|      * The method returns the customer's address, | ||||
|        only it doesn't find it the cache- addresses and directory. | ||||
|      * | ||||
|      * @param customer the customer | ||||
|      * @return the address | ||||
|      */ | ||||
| 
 | ||||
|    @Cacheable("addresses", “directory”) | ||||
|     @Cacheable("addresses", “directory”) | ||||
| 
 | ||||
|    public String getAddress1(Customer customer) { | ||||
|     public String getAddress1(Customer customer) { | ||||
| 
 | ||||
|      return customer.getAddress(); | ||||
|    } | ||||
|         return customer.getAddress(); | ||||
|     } | ||||
| 
 | ||||
| 	/** | ||||
| 	  * The method returns the customer's address, | ||||
| 	    but refreshes all the entries in the cache to load new ones. | ||||
|     * | ||||
| 		* @param customer the customer | ||||
| 		* @return the address | ||||
| 		*/ | ||||
|     /** | ||||
|      * The method returns the customer's address, | ||||
|         but refreshes all the entries in the cache to load new ones. | ||||
|      * | ||||
|      * @param customer the customer | ||||
|      * @return the address | ||||
|      */ | ||||
| 
 | ||||
| 	@CacheEvict(value="addresses", allEntries=true) | ||||
|     @CacheEvict(value="addresses", allEntries=true) | ||||
| 
 | ||||
| 	public String getAddress2(Customer customer) { | ||||
|     public String getAddress2(Customer customer) { | ||||
| 
 | ||||
| 		return customer.getAddress(); | ||||
| 	} | ||||
|         return customer.getAddress(); | ||||
|     } | ||||
| 
 | ||||
| 	/** | ||||
| 	  * The method returns the customer's address, | ||||
| 	    but not before selectively evicting the cache as per specified paramters. | ||||
| 		* | ||||
| 		* @param customer the customer | ||||
| 		* @return the address | ||||
| 		*/ | ||||
|     /** | ||||
|      * The method returns the customer's address, | ||||
|         but not before selectively evicting the cache as per specified paramters. | ||||
|      * | ||||
|      * @param customer the customer | ||||
|      * @return the address | ||||
|      */ | ||||
| 
 | ||||
| 	@Caching(evict = { @CacheEvict("addresses"), @CacheEvict(value="directory", key="customer.name") }) | ||||
|     @Caching(evict = { @CacheEvict("addresses"), @CacheEvict(value="directory", key="customer.name") }) | ||||
| 
 | ||||
| 	public String getAddress3(Customer customer) { | ||||
|     public String getAddress3(Customer customer) { | ||||
| 
 | ||||
| 		return customer.getAddress(); | ||||
| 	} | ||||
|         return customer.getAddress(); | ||||
|     } | ||||
| 
 | ||||
| 	/** | ||||
| 	* The method uses the class level cache to look up for entries. | ||||
| 	* | ||||
| 	* @param customer the customer | ||||
| 	* @return the address | ||||
| 	*/ | ||||
|     /** | ||||
|      * The method uses the class level cache to look up for entries. | ||||
|      * | ||||
|      * @param customer the customer | ||||
|      * @return the address | ||||
|      */ | ||||
| 
 | ||||
| 	@Cacheable // parameter not required as we have declared it using @CacheConfig | ||||
|     @Cacheable // parameter not required as we have declared it using @CacheConfig | ||||
| 
 | ||||
| 	public String getAddress4(Customer customer) { | ||||
|     public String getAddress4(Customer customer) { | ||||
| 
 | ||||
| 		return customer.getAddress(); | ||||
| 	} | ||||
|         return customer.getAddress(); | ||||
|     } | ||||
| 
 | ||||
| 	/** | ||||
| 	* The method selectively caches the results that meet the predefined criteria. | ||||
| 	* | ||||
| 	* @param customer the customer | ||||
| 	* @return the address | ||||
| 	*/ | ||||
|     /** | ||||
|      * The method selectively caches the results that meet the predefined criteria. | ||||
|      * | ||||
|      * @param customer the customer | ||||
|      * @return the address | ||||
|      */ | ||||
| 
 | ||||
| 
 | ||||
| 	@CachePut(value="addresses", condition=”#customer.name=’Tom’”) | ||||
| 	@CachePut(value="addresses", unless=”#result.length>64”) | ||||
|     @CachePut(value="addresses", condition=”#customer.name=’Tom’”) | ||||
|     @CachePut(value="addresses", unless=”#result.length>64”) | ||||
| 
 | ||||
| 	public String getAddress5(Customer customer) { | ||||
|     public String getAddress5(Customer customer) { | ||||
| 
 | ||||
| 		return customer.getAddress(); | ||||
| 	} | ||||
|         return customer.getAddress(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user