Simple session based data caching for spring mvc 3
I need simple, preferable session based cache, for our Spring MVC 3.1 app. I k开发者_高级运维now in 3.1 introduced cashing abstraction, but as far as I know, it is application wide caching. We need something simpler, for caching user grid data. I don't mined even using it directly, as long, as it has simple interface.
Any one used something like that? Is there any good lib? Or is there way to force Spring cache abstraction to cache data for current session only? Or am I doomed to write it by myself?
Session scoped bean
If you don't mind explicit solution, create a bean with session
scope and inject it to your controller.
If you don't forget to wrap it with scoped proxy (<aop:scoped-proxy/>
) you can
just place your cached data in fields of that bean. Spring will automatically create one instance of that bean per each HTTP session and store it there.
Caching abstraction
On the other hand I think Spring caching abstraction might work for you - SPeL gives you access to HTTP environment so you probably construct cache key declaratively (in annotation) based on current user session id or some other attribute like user name.
精彩评论