开发者

Where to cache : Database cache or App server using SessionScoped managed beans?

I am building web app using Casssandra DB & Java with JSF 2.0.

Cassandra has its own caching layer and also I can cache using SessionsScoped managed beans in JSF. I would like to know what would be a good way to 开发者_运维百科implement caching of data of different kinds: the to-be-cached data is sometimes quite big in size for 1 kind and sometimes it is small sized(2nd kind).

Since the cached data columns in Cassandra row would store the data in serialized format & with entire column structure, I guess I would be better storing them at the app server in session scoped beans whereby I can also have a better control of the cached data & cached data could be the most relevant and I guess it makes no difference in terms of the hardware requirements in the 2 cases:- (1) when I implement it using sessionscoped beans (2) if I use the DB cache.

Please list any differences in the benefits that may be there with these two caching implementations.


Do not (ab)use the session scope as cache for large datasets. You're basically duplicating the cache for every visitor. You should have a single cache. The DB cache is perfectly fine.

As to the size of the data, you should effectively have a request or view scoped bean which contains exactly the data the enduser needs to know about in the particular request. E.g. when you're displaying a dataset of 1000 objects through pagination with 10 objects per page, then the request scoped bean should contain exactly those 10 objects and the remnant should be kept there in the DB/DB cache. The code should also be written that way that it retrievs exactly those 10 objects (and thus don't retrieve 1000 objects and then filter the desired 10 out of it).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜