Web应用程序的特定缓存方案 [英] Specific Caching Scenario for Web Application

查看:46
本文介绍了Web应用程序的特定缓存方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Web应用程序,其中涉及能够从多个百货公司获取特定的计算机日志.该应用程序正在从SQL Server数据库获取数据.在应用程序启动时,我要求用户选择区域号以缩小选择范围.选择区域后,我将调用数据库以检索该区域中的其他商店(我创建了一个Store类,以便可以轻松创建对象).我向用户显示它们,以便他们可以选择所需的商店.用户选择商店后,我必须再次调用数据库以检索属于该商店的工作站列表(同样,我定义了一个名为Workstation的类).然后,用户可以选择一个工作站,选择要从中选择日志的日期和月份,然后单击提交"按钮.

I am making a web application that involves being able to grab specific computer logs from multiple department stores. The application is getting data from a SQL Server DB. At the start of the app I ask the user to select a region number to narrow down their choices. After the region selection is made I make a call to the DB to retrieve the different stores in that area (I have made a Store class so I can create objects easily). I display them to the user so they can make their choice of which store they want. After the user chooses their store, I have to call the DB again to retrieve a list of workstations that belong to that store (again I have a class defined called Workstation). Then the user can select a workstation, pick a day and month they want a log from and hit a submit button.

当涉及到从数据库缓存结果时,我对如何执行此操作感到困惑.理想情况下,我将使用某些缓存管理器(如JCS或EHCACHE)来缓存Store和Workstation对象.我获取存储的第一个SQL语句具有WHERE子句,用于检查用户选择的REGION.因此,当我将这些结果返回到ResultSet对象中时,是否要一个接一个地遍历它们,并检查它们是否已在缓存中?如果它们不在其中,则创建一个Store对象并添加它.如果对象已经在缓存中,则使用continue语句跳至ResultSet的下一个迭代?

When it comes to caching results from the DB I am confused on how to do this. Ideally I'd be caching Store and Workstation objects with some cache manager like JCS or EHCACHE. My first SQL statement to get the stores has a WHERE clause checking the REGION the user selected. So, As I get these results back in a ResultSet object do I iterate through them one by one and check if they're already in the cache? If they aren't in there then create a Store object and add it. If the object is already in cache then use a continue statement to skip to the next iteration of the ResultSet?

并且您认为考虑是否在过去的某天和某个月需要缓存日志信息是否更明智?

And do you think it would even be wise to consider caching log info that was asked for on a certain day and month if it's in the past?

我正在寻找有关如何继续该项目的指导,如果有人可以帮助我或为我提供一般性的实施建议或建议,我将非常感激.编程本身不是问题.只是我不熟悉缓存本身.

I'm looking for some guidance on how to continue this project and I would really appreciate it if someone could help me out or give me a general walk through or recommendation on how to proceed. The programming itself is not the problem. It's just my unfamiliarity with caching itself.

非常感谢!

推荐答案

然后,用户可以选择一个工作站,选择他们想要从中登录的日期和月份,然后单击提交"按钮.

Then the user can select a workstation, pick a day and month they want a log from and hit a submit button.

基于此陈述,我假设将特定日期和月份的日志一旦写入数据库就不会更新.

Based on this statement, I am assuming that the log for a particular day and month will not be updated once it has been written to the database.

因此,当我将这些结果返回到ResultSet对象中时,是否要逐个进行遍历并检查它们是否已在缓存中?

So, As I get these results back in a ResultSet object do I iterate through them one by one and check if they're already in the cache?

似乎将Hibernate与第二级缓存一起使用,查询缓存将是一个更好的选择,而不是仅使用缓存.由于您的问题是一个高级别的问题,因此我不会详细介绍什么是Hibernate以及如何使我们休眠并配置二级缓存和查询缓存.

It looks like using Hibernate with a second level cache and query caching would be a better option for you instead of using just a cache. Since your question is a high level question, I am not going to get into the details of what is Hibernate and how to us Hibernate and configure a second level cache and a query cache.

有关查询缓存的更多详细信息,请参见.这篇文章有点老,但是确实帮助我了解了查询缓存的基础.

See this for more details on query cache. The article is a bit old but it did help me understand the basics of query caching.

并且您认为考虑是否在过去的某天和某个月需要缓存日志信息是否更明智?

And do you think it would even be wise to consider caching log info that was asked for on a certain day and month if it's in the past?

我认为缓存过去的数据没有任何问题.缓存数据的主要目的是使应用程序所需的数据在需要时快速可用.如果访问此数据需要您每次访问数据库时都访问数据库或从文件中读取数据,则缓存是有意义的.

I don't think there is anything wrong in caching past data. The primary purpose of caching data is to make data required by your application available quickly when it is required. If accessing this data requires you to hit the database or read from a file everytime the data is required, a cache makes sense.

这篇关于Web应用程序的特定缓存方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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