简体   繁体   English

缓存位置:使用SessionScoped托管bean的数据库缓存或App服务器?

[英]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 . 我正在使用带有JSF 2.0的 Casssandra DB和Java构建Web应用程序。

Cassandra has its own caching layer and also I can cache using SessionsScoped managed beans in JSF. Cassandra有自己的缓存层,我也可以在JSF中使用SessionsScoped托管bean进行缓存。 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). 我想知道什么是实现不同类型数据缓存的好方法:待缓存数据有时相当大1种,有时它是小尺寸(第2种)。

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. 由于Cassandra行中的缓存数据列将以序列化格式存储数据并具有整个列结构,我想我会更好地将它们存储在会话范围bean中的app服务器上,从而我可以更好地控制缓存数据和缓存数据可能是最相关的,我想在两种情况下硬件要求没有区别: - (1)当我使用sessioncoped bean(2)实现它时,如果我使用数据库缓存。

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. 不要(ab)将会话范围用作大型数据集的缓存。 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. 至于数据的大小,你应该切实有一个请求或视图范围的bean包含完全相同的最终用户需要了解在特定请求的数据。 Eg 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. 例如,当您通过每页10个对象的分页显示1000个对象的数据集时,请求范围的bean应该包含这10个对象,并且应该将剩余部分保存在DB / DB缓存中。 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). 代码也应该以这样的方式编写,即它正好检索那10个对象(因此不会检索1000个对象,然后过滤掉所需的10个对象)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM