CDI 拦截器和 memcache
我正在阅读有关拦截器和 AOP 的内容,它们可以整理代码并将横切关注点具体化为方面。我立即想到了 CDI 以及每次尝试访问数据库时使用自定义拦截器来访问缓存的方法。 是否有任何库已经实现了此功能并支持 memcache?我认为应该拦截对实体管理器的调用。
I was reading about interceptors and AOP, the way they can unclutter your code and externalize cross-cutting concerns into aspects. I instantly thought of CDI and the use of custom interceptors to access cache everytime one tries to access the database.
Is there any library that already implements this and supports memcache? I think calls to the entitymanager should be intercepted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恕我直言,如果您想这样做,您需要一个很好的理由来证明为什么 Hibernate Cache / JBoss Cache(只是猜测您的技术堆栈,但几乎所有堆栈都有产品/解决方案)不适合您的需求?
您当然不想在开发自己的查询或对象缓存方面重新发明轮子,不是吗?
IMHO, if you want to go that way, you need a pretty good reason to justify why Hibernate Cache / JBoss Cache (just guessing about your technology stack, but there are products / solution for almost all stacks) won't fit you needs?
You certainly don't want to reinvent the wheel in terms of developing your own query- or object cache, don't you?
一般来说,使用memcached直接避免DB请求是非常困难且低效的。您确实想要缓存更高级别的概念,例如 DAO -> DTO 边界。
我已经使用 AOP 在 java 程序中非常成功地注入缓存失效和观察者管理代码。 AOP 允许我考虑代码不同部分的不同的可重用性。这并不意味着我不必设计这些方面,但它使我摆脱了限制并阻止我剪切和粘贴等......
所以我的建议是设计这种访问模式,这样你就必须做在每个边界上进行一堆工作,然后设计横切以在编译时注入该工作。
In general, using memcached to directly avoid DB requests is very difficult to get right and inefficient. You really want to cache higher level concepts such as DAO -> DTO boundaries.
I've used AOP to inject cache invalidation and observer management code in java programs pretty successfully. AOP allows me to think of a different set of reusability of different parts of my code. It doesn't mean I don't have to design these aspects, but it frees me of limitations and prevents me from cutting and pasting, etc...
So my recommendation would be to design this access pattern such that you have to do a bunch of work at each of these boundaries, and then design cross cuts that inject that work at compile time.