简体   繁体   English

在会话中存储大量数据-我应该这样做吗?

[英]Storing Large Amount of Data in Session - Should I Do This?

High level question here - I am developing a Spring MVC/Spring Data Project to search Tables in a database via Spring Repositories. 这里的高级问题-我正在开发一个Spring MVC / Spring Data Project,以通过Spring Repositories搜索数据库中的表。 The tables I am searching on will contain thousands, if not tens of thousands of records. 我正在搜索的表将包含成千上万个记录,甚至上万个记录。 I would like to hold onto these records in a List throughout the duration of using the application, until a condition is met where the List will be reset or removed. 在整个应用程序使用过程中,我都希望保留List中的这些记录,直到满足重置或删除List的条件为止。

My question is, is it feasible to store this List in my HttpSession ? 我的问题是,将此List存储在我的HttpSession是否可行?

  • Should I expect any performance issues with this method? 我应该期望这种方法有任何性能问题吗?
  • Is there a security concern if storing my List in the session? 如果将我的List存储在会话中,是否存在安全问题?
  • Are there any best practices anyone can offer for a task such as this? 任何人都可以为此类任务提供最佳实践吗?

A quick view of the user session info along side a small List of 4 objects (could potentially be thousands) 快速查看用户会话信息以及4个对象的小型列表(可能是数千个)

Session Attribute Name  Session Attribute Value
searchResults           [com.mysite.dto.User@322bfb87,
                         com.mysite.dto.User@658e75cc, 
                         com.mysite.dto.User@6bd7d82a, 
                         com.mysite.dto.User@27b0e4b6]
userRoles               [ROLE_ADMIN]
username                admin

Thanks in advance 提前致谢

i would store them in a cache but not in session. 我会将它们存储在缓存中,而不是会话中。 You can use external caches like BigMemory Terracotta ( http://terracotta.org/products/bigmemory ) or memcache (Amazon provides an easy to use one if you are running your application in the EC2). 您可以使用外部缓存,例如BigMemory Terracotta( http://terracotta.org/products/bigmemory )或memcache(如果您在EC2中运行应用程序,Amazon提供了一种易于使用的缓存)。 This will be much more scale able than your servers JVM heap. 这将比您的服务器JVM堆具有更大的扩展能力。

another idea would be to store in cache a reference of the user id with the user object and now in session you can store only the ids. 另一个想法是将用户ID与用户对象的引用存储在缓存中,现在在会话中您只能存储ID。 That way your session saves only numbers instead of whole objects 这样,您的会话仅保存数字,而不是整个对象

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

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