我正在spring-data-couchbase 2.1.2
使用spring-boot 1.4.0.RC1
和couchbase-spring-cache
当禁用缓存时,它正常工作,因为它返回NULL对象当启用缓存并尝试在存储桶中查找不存在的文档时,它会引发异常:
com.couchbase.client.java.error.DocumentDoesNotExistException: null
at com.couchbase.client.java.CouchbaseAsyncBucket$22.call(CouchbaseAsyncBucket.java:684) ~[java-client-2.2.8.jar:na]
at com.couchbase.client.java.CouchbaseAsyncBucket$22.call(CouchbaseAsyncBucket.java:671) ~[java-client-2.2.8.jar:na]
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:54) ~[rxjava-1.0.17.jar:1.0.17]
at rx.observers.Subscribers$5.onNext(Subscribers.java:234) ~[rxjava-1.0.17.jar:1.0.17]
at rx.subjects.SubjectSubscriptionManager$SubjectObserver.onNext(SubjectSubscriptionManager.java:223) ~[rxjava-1.0.17.jar:1.0.17]
at rx.subjects.AsyncSubject.onCompleted(AsyncSubject.java:101) ~[rxjava-1.0.17.jar:1.0.17]
at com.couchbase.client.core.endpoint.AbstractGenericHandler.completeResponse(AbstractGenericHandler.java:354) ~[core-io-1.2.9.jar:na]
at com.couchbase.client.core.endpoint.AbstractGenericHandler.access$000(AbstractGenericHandler.java:72) ~[core-io-1.2.9.jar:na]
at com.couchbase.client.core.endpoint.AbstractGenericHandler$1.call(AbstractGenericHandler.java:372) ~[core-io-1.2.9.jar:na]
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) ~[rxjava-1.0.17.jar:1.0.17]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_80]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) ~[na:1.7.0_80]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) ~[na:1.7.0_80]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) ~[na:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_80]
at java.lang.Thread.run(Thread.java:745) ~[na:1.7.0_80]
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.couchbase.client.core.message.kv.RemoveResponse.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:109) ~[rxjava-1.0.17.jar:1.0.17]
at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:188) ~[rxjava-1.0.17.jar:1.0.17]
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:56) ~[rxjava-1.0.17.jar:1.0.17]
... 14 common frames omitted
是不是因为AsyncBucket?是否可以禁用AsyncBucket?
答案 0 :(得分:4)
这确实是一个问题......只要对不在缓存中的密钥进行驱逐尝试,就会抛出异常:(
我为此创建了an issue(有解决方法)。
编辑:要解决此问题,您应该能够声明CacheErrorHandler
具有handleCacheEvictError
方法的DocumentDoesNotExistException
方法,只需捕获example = ['ab', 'cd']
res1={x[1]:x[0] for x in example}
res2={x[0]:x[1] for x in example}
res=res1.update(res2)
print res1
。
请参阅有关配置缓存抽象here和CachingConfigurer
javadoc。
答案 1 :(得分:0)
我遇到了同样的异常,用例是我正在缓存返回null的资源,例如:
@Override
@Cacheable(value = "EMPLOYEE_", key = "#id")
public Employee getEmployee(int id) {
return null;
}
使用pip.conf的unless
属性修复它,该属性从 Spring 3.2 开始提供,如下所示:
@Override
@Cacheable(value = "EMPLOYEE_", key = "#id", unless = "#result == null")
public Employee getEmployee(int id) {
return null;
}
还写了一篇文章来描述我的问题并修复了同样的问题 - @Cacheable