Struts2静态数据存储/访问 [英] Struts2 static data storage / access

查看:113
本文介绍了Struts2静态数据存储/访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到静态/全局的常用设计/方法! Web应用程序中的数据访问/存储,我正在使用struts 2.背景,我想在我的Web应用程序中显示许多表。

I am trying to find what is the usual design/approach for "static/global"! data access/storage in a web app, I'm using struts 2. Background, I have a number of tables I want to display in my web app.

问题1 。
这些表只会在服务器上每天更改一次并更新一次,我不想访问数据库/或为查看表的每个请求加载文件。
我更喜欢将表加载到某个全局内存/缓存一次(一天),每个请求从那里获取表,而不是访问数据库。
我想这是一个常见的场景,并且有一种既定的方法?但我现在无法找到它。
对于struts 2,ActionContext是否适合此数据。
如果是这样,任何指向教程的链接都会非常感激。

Problem 1. The tables will only change and be updated once a day on the server, I don't want to access a database/or loading a file for every request to view a table. I would prefer to load the tables to some global memory/cache once (a day), and each request get the table from there, rather than access a database. I imagine this is a common scenario and there is an established approach? But I cant find it at the moment. For struts 2, Is the ActionContext the right place for this data. If so, any link to a tutorial would be really appreciated.

问题2.
这些表存储在我解组的XML文件中JAXB获取表对象,以及表的列表。
对于一个小应用程序,这没关系,但我认为对于Web应用程序来说,将xml存储为资源并将其作为servlet上下文和解析文件读入是hacky,还是它?
我意识到可能会告诉我将表存储到使用dao访问的数据库中,并使用hibernate来获取对象。
我只是对数据已存储在XML文件中的常用方法感到好奇吗?鉴于我每天都会有新的XML文件。

Problem 2. The tables were stored in a XML file I unmarshalled with JAXB to get the table objects, and so the lists for the tables. For a small application this was OK, but I think for the web app, its hacky to store the xml as resources and read in the file as servlet context and parse, or is it? I realise I may be told to store the tables to a database accessing with a dao, and use hibernate to get the objects. I am just curious as to what is the usual approach with data already stored in XML file? Given I will have new XML files daily.

道歉,如果问题是基本的,我有大量的书籍/参考资料,但它只是花时间去获取更高层次的设计答案。

Apologies if the questions are basic, I have a large amount of books/reference material, but its just taking me time to get the higher level design answers.

推荐答案

这根本不是特定于Struts2的。您绝对不想尝试将此信息存储在 ActionContext 中 - 这是一个每请求对象。

This isn't really specific to Struts2 at all. You definitely do not want to try storing this information in the ActionContext -- that's a per-request object.

你应该研究一下像EHCache这样的缓存框架。如果您使用Hibernate进行持久化,Hibernate可以选择缓存数据,这样就不需要在每次请求时都访问数据库。 (Hibernate也可以将EHCache用于其二级缓存)。

You should look into a caching framework like EHCache or something similar. If you use Hibernate for your persistence, Hibernate has options for caching data so that it does not need to hit the database on every request. (Hibernate can also use EHCache for its second-level cache).

这篇关于Struts2静态数据存储/访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆