In a server-side application running on Tomcat, I am generating full HTML pages (with header) based on random user-requested sites pulled down from the Internet. The client-side application uses asynchronous callbacks for requesting processing of a particular web page. Since processing can take a while, I want to inform the user about progress via polling, hence the callbacks.
在Tomcat上运行的服务器端应用程序中,我基于从Internet下载的随机用户请求的站点生成完整的HTML页面(带有标题)。客户端应用程序使用异步回调来请求处理特定网页。由于处理可能需要一段时间,我想通过轮询通知用户进度,因此回调。
On server-side, after the web page is retrieved, it is processed and an "enhanced" version is created. Then this version has to go back to the user. Displaying the page as part of the page of the client-side application is not an option.
在服务器端,在检索网页后,将对其进行处理并创建“增强”版本。然后这个版本必须返回给用户。将页面显示为客户端应用程序页面的一部分不是一种选择。
Currently, the server generates a temporary file and sends back a link to it. This is clearly suboptimal.
目前,服务器生成一个临时文件并发回一个链接。这显然不是最理想的。
The next best solution I can come up with inolves creating a caching-DB that stores the HTML content together with its md5-sums or sha1-ids and then sends back a link to a servlet, with the hash-ID as an argument. The servlet then requests the site from the caching-DB.
我可以提出下一个最佳解决方案inolves创建一个缓存DB,它将HTML内容与md5-sums或sha1-id一起存储,然后发送回一个servlet的链接,并将hash-ID作为参数。然后,servlet从缓存DB请求站点。
Is there any better solution? If not, which DB-backend would you propose? I'm thinking of SQLite. Part of the problem to be solved is: how do I push a page <html>
to </html>
back to client side?
有没有更好的解决方案?如果没有,你会建议哪个DB-backend?我在考虑SQLite。要解决的部分问题是:如何将页面推送到 回到客户端?
2 个解决方案
#1
1
If true persistence isn't required how about using something more temporal like memcached instead of SQL? Calling semantics are pretty clean and easy - and of course you can expire the data manually, ttl, or @ restart.
如果不需要真正的持久性如何使用更像memcached而不是SQL的时态?调用语义非常简洁 - 当然,您可以手动,ttl或@ restart使数据过期。
#2
1
Instead of creating a temporary file, filling it up, and then sending a link, you can create a memory buffer, fill it up, and then send that as the response (serve it with mime-type 'text/html'). If you don't want to send page-buffers immediately, you can save them for later in the user's session. If you're worried of taking up too much memory that way, you may want to keep only a certain number of page-buffers around in memory, and write the rest to disk for later retrieval. Using a DB sounds like overkill (after all, there's no relational information involved) - but it would solve the caching problem nicely.
您可以创建一个内存缓冲区,填充它,然后将其作为响应发送(使用mime-type'text / html'提供),而不是创建临时文件,填充它,然后发送链接。如果您不想立即发送页面缓冲区,可以将它们保存以供以后在用户的会话中使用。如果您担心以这种方式占用太多内存,您可能希望在内存中只保留一定数量的页面缓冲区,并将其余内容写入磁盘以供以后检索。使用数据库听起来有点过分(毕竟,没有涉及关系信息) - 但它可以很好地解决缓存问题。
#1
1
If true persistence isn't required how about using something more temporal like memcached instead of SQL? Calling semantics are pretty clean and easy - and of course you can expire the data manually, ttl, or @ restart.
如果不需要真正的持久性如何使用更像memcached而不是SQL的时态?调用语义非常简洁 - 当然,您可以手动,ttl或@ restart使数据过期。
#2
1
Instead of creating a temporary file, filling it up, and then sending a link, you can create a memory buffer, fill it up, and then send that as the response (serve it with mime-type 'text/html'). If you don't want to send page-buffers immediately, you can save them for later in the user's session. If you're worried of taking up too much memory that way, you may want to keep only a certain number of page-buffers around in memory, and write the rest to disk for later retrieval. Using a DB sounds like overkill (after all, there's no relational information involved) - but it would solve the caching problem nicely.
您可以创建一个内存缓冲区,填充它,然后将其作为响应发送(使用mime-type'text / html'提供),而不是创建临时文件,填充它,然后发送链接。如果您不想立即发送页面缓冲区,可以将它们保存以供以后在用户的会话中使用。如果您担心以这种方式占用太多内存,您可能希望在内存中只保留一定数量的页面缓冲区,并将其余内容写入磁盘以供以后检索。使用数据库听起来有点过分(毕竟,没有涉及关系信息) - 但它可以很好地解决缓存问题。