cập nhật câu trả lời này là lỗi thời bây giờ, cho mùa xuân 3.2 và sau hãy xem answer, OP: Hãy cảm thấy tự do để đánh dấu nó là được chấp nhận.
Tôi không nghĩ rằng nó có thể (mặc dù có điều kiện cache đuổi trong mùa xuân có thể được thực hiện sau khi phương pháp gọi với @CacheEvict
tham số beforeInvocation thiết lập để sai sự thật, đó là giá trị mặc định) kiểm tra các lớp CacheAspectSupport
cho thấy giá trị trả lại không được lưu trữ ở bất kỳ đâu trước cuộc gọi inspectAfterCacheEvicts(ops.get(EVICT));
.
protected Object execute(Invoker invoker, Object target, Method method, Object[] args) {
// check whether aspect is enabled
// to cope with cases where the AJ is pulled in automatically
if (!this.initialized) {
return invoker.invoke();
}
// get backing class
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target);
if (targetClass == null && target != null) {
targetClass = target.getClass();
}
final Collection<CacheOperation> cacheOp = getCacheOperationSource().getCacheOperations(method, targetClass);
// analyze caching information
if (!CollectionUtils.isEmpty(cacheOp)) {
Map<String, Collection<CacheOperationContext>> ops = createOperationContext(cacheOp, method, args, target, targetClass);
// start with evictions
inspectBeforeCacheEvicts(ops.get(EVICT));
// follow up with cacheable
CacheStatus status = inspectCacheables(ops.get(CACHEABLE));
Object retVal = null;
Map<CacheOperationContext, Object> updates = inspectCacheUpdates(ops.get(UPDATE));
if (status != null) {
if (status.updateRequired) {
updates.putAll(status.cUpdates);
}
// return cached object
else {
return status.retVal;
}
}
retVal = invoker.invoke();
inspectAfterCacheEvicts(ops.get(EVICT));
if (!updates.isEmpty()) {
update(updates, retVal);
}
return retVal;
}
return invoker.invoke();
}
Nguồn
2012-08-24 17:52:04
Xin chào, tôi nghĩ bạn nên trả lời câu hỏi của Tech Trip khi được chấp nhận vì nó phù hợp hơn với phiên bản Spring hiện tại. –