How to handle code when memchache is not working(simple-spring-memcached)

给你一囗甜甜゛ 提交于 2019-12-25 05:07:19

问题


Thanks to the 'Getting started guide' in ‘simple-spring-memcached’ I manage to get memcached working in my project using ‘Spring 3.1’ example in in the guide , Im using ‘spymemcached’ as the provider . All working well when memcached server is up and running. However, when memcache server is not accessible (deliberately shut down for testing) underline code doesn’t work and application wont execute simply throwing runtime exception ,stating that unable to connect to memcache server and timeout happen .

Caused by: net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting

However what I expect in this scenario is to target method to be executed every time as cache is unreachable than completly blocking the execution path. Is this possible using simple spring memcache ? , has any one got experience with this ? how do I solve this situation , Any exception in cache layer no need to disturb the execution, simply need to call the target method as a fall-back. This is what I’m trying to achieve.

I tried spring ‘CompositeCacheManager’ with ‘fallbackToNoOpCache’ but it looks like simple-spring-memcached has no effect on this .

All my configuration is exactly similar to (spring 3.1 )

https://code.google.com/p/simple-spring-memcached/wiki/Getting_Started

Thanks for your help

eg : usage of my @Cacheable is

@Cacheable(value="books", key="#isbn")
public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)

回答1:


You are right it should work as you have described it and I'm sure that in case of SSM annotations (@ReadThrough*, @Update*, @Invalidate*) it works in that way. I see that for Spring Cache annotations the behavior is different . I'll try to fix it today. If you don't mind could you please create an issue for this bug on github SSM page.



来源:https://stackoverflow.com/questions/22327168/how-to-handle-code-when-memchache-is-not-workingsimple-spring-memcached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!