@@ -135,8 +135,8 @@ public void afterPropertiesSet() {
135
135
throw new IllegalStateException ("'cacheManager' is required" );
136
136
}
137
137
if (this .cacheOperationSource == null ) {
138
- throw new IllegalStateException ("The 'cacheOperationSources' property is required: "
139
- + "If there are no cacheable methods, then don't use a cache aspect." );
138
+ throw new IllegalStateException ("The 'cacheOperationSources' property is required: " +
139
+ "If there are no cacheable methods, then don't use a cache aspect." );
140
140
}
141
141
142
142
this .initialized = true ;
@@ -163,7 +163,7 @@ protected Collection<Cache> getCaches(CacheOperation operation) {
163
163
for (String cacheName : cacheNames ) {
164
164
Cache cache = this .cacheManager .getCache (cacheName );
165
165
if (cache == null ) {
166
- throw new IllegalArgumentException ("Cannot find cache named [ " + cacheName + "] for " + operation );
166
+ throw new IllegalArgumentException ("Cannot find cache named ' " + cacheName + "' for " + operation );
167
167
}
168
168
caches .add (cache );
169
169
}
@@ -188,7 +188,7 @@ protected Object execute(Invoker invoker, Object target, Method method, Object[]
188
188
if (targetClass == null && target != null ) {
189
189
targetClass = target .getClass ();
190
190
}
191
- final Collection <CacheOperation > cacheOp = getCacheOperationSource ().getCacheOperations (method , targetClass );
191
+ Collection <CacheOperation > cacheOp = getCacheOperationSource ().getCacheOperations (method , targetClass );
192
192
193
193
// analyze caching information
194
194
if (!CollectionUtils .isEmpty (cacheOp )) {
@@ -237,7 +237,6 @@ private void inspectCacheEvicts(Collection<CacheOperationContext> evictions, boo
237
237
// for each cache
238
238
// lazy key initialization
239
239
Object key = null ;
240
-
241
240
for (Cache cache : context .getCaches ()) {
242
241
// cache-wide flush
243
242
if (evictOp .isCacheWide ()) {
@@ -284,9 +283,8 @@ private CacheStatus inspectCacheables(Collection<CacheOperationContext> cacheabl
284
283
logger .trace ("Computed cache key " + key + " for operation " + context .operation );
285
284
}
286
285
if (key == null ) {
287
- throw new IllegalArgumentException (
288
- "Null key returned for cache operation (maybe you are using named params on classes without debug info?) "
289
- + context .operation );
286
+ throw new IllegalArgumentException ("Null key returned for cache operation (maybe you " +
287
+ "are using named params on classes without debug info?) " + context .operation );
290
288
}
291
289
// add op/key (in case an update is discovered later on)
292
290
cacheUpdates .put (context , key );
@@ -313,7 +311,7 @@ private CacheStatus inspectCacheables(Collection<CacheOperationContext> cacheabl
313
311
}
314
312
}
315
313
316
- // return a status only if at least on cacheable matched
314
+ // return a status only if at least one cacheable matched
317
315
if (atLeastOnePassed ) {
318
316
return new CacheStatus (cacheUpdates , updateRequired , retVal );
319
317
}
@@ -333,9 +331,8 @@ private Map<CacheOperationContext, Object> inspectCacheUpdates(Collection<CacheO
333
331
logger .trace ("Computed cache key " + key + " for operation " + context .operation );
334
332
}
335
333
if (key == null ) {
336
- throw new IllegalArgumentException (
337
- "Null key returned for cache operation (maybe you are using named params on classes without debug info?) "
338
- + context .operation );
334
+ throw new IllegalArgumentException ("Null key returned for cache operation (maybe you " +
335
+ "are using named params on classes without debug info?) " + context .operation );
339
336
}
340
337
// add op/key (in case an update is discovered later on)
341
338
cacheUpdates .put (context , key );
@@ -353,44 +350,39 @@ private Map<CacheOperationContext, Object> inspectCacheUpdates(Collection<CacheO
353
350
private void update (Map <CacheOperationContext , Object > updates , Object retVal ) {
354
351
for (Map .Entry <CacheOperationContext , Object > entry : updates .entrySet ()) {
355
352
CacheOperationContext operationContext = entry .getKey ();
356
- if (operationContext .canPutToCache (retVal )) {
353
+ if (operationContext .canPutToCache (retVal )) {
357
354
for (Cache cache : operationContext .getCaches ()) {
358
355
cache .put (entry .getValue (), retVal );
359
356
}
360
357
}
361
358
}
362
359
}
363
360
364
- private Map <String , Collection <CacheOperationContext >> createOperationContext (Collection <CacheOperation > cacheOp ,
365
- Method method , Object [] args , Object target , Class <?> targetClass ) {
366
-
367
- Map <String , Collection <CacheOperationContext >> map = new LinkedHashMap <String , Collection <CacheOperationContext >>(3 );
361
+ private Map <String , Collection <CacheOperationContext >> createOperationContext (
362
+ Collection <CacheOperation > cacheOperations , Method method , Object [] args , Object target , Class <?> targetClass ) {
368
363
364
+ Map <String , Collection <CacheOperationContext >> result = new LinkedHashMap <String , Collection <CacheOperationContext >>(3 );
369
365
Collection <CacheOperationContext > cacheables = new ArrayList <CacheOperationContext >();
370
366
Collection <CacheOperationContext > evicts = new ArrayList <CacheOperationContext >();
371
367
Collection <CacheOperationContext > updates = new ArrayList <CacheOperationContext >();
372
368
373
- for (CacheOperation cacheOperation : cacheOp ) {
369
+ for (CacheOperation cacheOperation : cacheOperations ) {
374
370
CacheOperationContext opContext = getOperationContext (cacheOperation , method , args , target , targetClass );
375
-
376
371
if (cacheOperation instanceof CacheableOperation ) {
377
372
cacheables .add (opContext );
378
373
}
379
-
380
374
if (cacheOperation instanceof CacheEvictOperation ) {
381
375
evicts .add (opContext );
382
376
}
383
-
384
377
if (cacheOperation instanceof CachePutOperation ) {
385
378
updates .add (opContext );
386
379
}
387
380
}
388
381
389
- map .put (CACHEABLE , cacheables );
390
- map .put (EVICT , evicts );
391
- map .put (UPDATE , updates );
392
-
393
- return map ;
382
+ result .put (CACHEABLE , cacheables );
383
+ result .put (EVICT , evicts );
384
+ result .put (UPDATE , updates );
385
+ return result ;
394
386
}
395
387
396
388
@@ -430,8 +422,7 @@ protected boolean isConditionPassing() {
430
422
protected boolean isConditionPassing (Object result ) {
431
423
if (StringUtils .hasText (this .operation .getCondition ())) {
432
424
EvaluationContext evaluationContext = createEvaluationContext (result );
433
- return evaluator .condition (this .operation .getCondition (), this .method ,
434
- evaluationContext );
425
+ return evaluator .condition (this .operation .getCondition (), this .method , evaluationContext );
435
426
}
436
427
return true ;
437
428
}
@@ -444,7 +435,7 @@ protected boolean canPutToCache(Object value) {
444
435
else if (this .operation instanceof CachePutOperation ) {
445
436
unless = ((CachePutOperation ) this .operation ).getUnless ();
446
437
}
447
- if (StringUtils .hasText (unless )) {
438
+ if (StringUtils .hasText (unless )) {
448
439
EvaluationContext evaluationContext = createEvaluationContext (value );
449
440
return !evaluator .unless (unless , this .method , evaluationContext );
450
441
}
@@ -464,8 +455,7 @@ protected Object generateKey() {
464
455
}
465
456
466
457
private EvaluationContext createEvaluationContext (Object result ) {
467
- return evaluator .createEvaluationContext (this .caches , this .method , this .args ,
468
- this .target , this .targetClass , result );
458
+ return evaluator .createEvaluationContext (this .caches , this .method , this .args , this .target , this .targetClass , result );
469
459
}
470
460
471
461
protected Collection <Cache > getCaches () {
0 commit comments