22
33import org .springframework .beans .factory .annotation .Autowired ;
44import org .springframework .cache .CacheManager ;
5+ import org .springframework .cache .annotation .CacheConfig ;
6+ import org .springframework .cache .annotation .CacheEvict ;
7+ import org .springframework .cache .annotation .CachePut ;
58import org .springframework .cache .annotation .Cacheable ;
6- import org .springframework .context . ApplicationContext ;
9+ import org .springframework .cache . annotation . Caching ;
710import org .springframework .stereotype .Component ;
811
912@ Component
10- @ CacheConfig ("addressDemo" )
13+ @ CacheConfig (cacheNames = { "addressDemo" } )
1114public class CustomerDataService {
1215
1316 @ Autowired
@@ -20,8 +23,8 @@ public class CustomerDataService {
2023 * @param customer the customer
2124 * @return the address
2225 */
23- @ Cacheable ("addresses" , “ directory ” )
24- public String getAddress1 (Customer customer ) {
26+ @ Cacheable ({ "addresses" , " directory" } )
27+ public String getAddress1 (final Customer customer ) {
2528 return customer .getAddress ();
2629 }
2730
@@ -32,8 +35,8 @@ public String getAddress1(Customer customer) {
3235 * @param customer the customer
3336 * @return the address
3437 */
35- @ CacheEvict (value = "addresses" , allEntries = true )
36- public String getAddress2 (Customer customer ) {
38+ @ CacheEvict (value = "addresses" , allEntries = true )
39+ public String getAddress2 (final Customer customer ) {
3740 return customer .getAddress ();
3841 }
3942
@@ -44,8 +47,8 @@ public String getAddress2(Customer customer) {
4447 * @param customer the customer
4548 * @return the address
4649 */
47- @ Caching (evict = { @ CacheEvict ("addresses" ), @ CacheEvict (value = "directory" , key = "customer.name" ) })
48- public String getAddress3 (Customer customer ) {
50+ @ Caching (evict = { @ CacheEvict ("addresses" ), @ CacheEvict (value = "directory" , key = "customer.name" ) })
51+ public String getAddress3 (final Customer customer ) {
4952 return customer .getAddress ();
5053 }
5154
@@ -55,8 +58,9 @@ public String getAddress3(Customer customer) {
5558 * @param customer the customer
5659 * @return the address
5760 */
58- @ Cacheable // parameter not required as we have declared it using @CacheConfig
59- public String getAddress4 (Customer customer ) {
61+ @ Cacheable
62+ // parameter not required as we have declared it using @CacheConfig
63+ public String getAddress4 (final Customer customer ) {
6064 return customer .getAddress ();
6165 }
6266
@@ -66,9 +70,9 @@ public String getAddress4(Customer customer) {
6670 * @param customer the customer
6771 * @return the address
6872 */
69- @ CachePut (value = "addresses" , condition =” #customer .name =’ Tom ’” )
70- @ CachePut (value = "addresses" , unless =” #result .length >64 ” )
71- public String getAddress5 (Customer customer ) {
73+ @ CachePut (value = "addresses" , condition = " #customer.name=' Tom'" )
74+ // @CachePut(value = "addresses", unless = " #result.length>64" )
75+ public String getAddress5 (final Customer customer ) {
7276 return customer .getAddress ();
7377 }
7478}
0 commit comments