缓存样的机制(其中数据结构)? [英] Cache like mechanism (which Data Structure)?

查看:130
本文介绍了缓存样的机制(其中数据结构)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我取出由服务器(数据库)的一些问题,并显示给客户端(用户)中的浏览器。客户端将回答这个问题,并根据他/她的回答下一组问题将被从数据库中获取。现在,我想pre取下一组的问题,而用户读取present问题,这样的等待时间为用户能够看到下一个问题会更短。

I am fetching some questions from the server (database) and showing it to client (user) in the browser. The client will answer the question and based on his/her answer the next set of questions will be fetched from the database. Now, I want to pre-fetch the next set of questions while the user read the present question so that the waiting time for user to see the next question will be shorter.

我的问题是,如何存储pre牵强的问题,即它的数据结构,我应该用它来存储pre牵强问题的内存,这样我可以得到更好的性能?我希望有一个缓存之类的东西。此外,一旦用户的点击任何从缓存问题的问题将不会存在了。

My questions is, how to store the pre-fetched questions i.e. which data structure should I use to store the pre-fetched questions in the memory so that I can get better performance? I want a "cache" type of thing. Also once the user hit any question from the cache the question won't be there any more.

PS:每个问题都有唯一的ID

PS: Each question has unique Id.

感谢

纳文

推荐答案

有多种选择去了解它。一个使一个很大的区别,一个没有什么。

There are multiple options to go about it. One that makes a big difference, one that makes little.

  • 小区别是获取问题,并将其存储在用户的会话。这基本上取决于其中会话被存储,也可以是数据库,或一个文件。这仅是有道理的,如果你的数据库表是非常非规范化的,它需要大量的连接来得到答案。我怀疑是这种情况所以这不会让无论数据结构使用哪个用户太大的区别。

  • Little difference would be to fetch questions and store it in user's session. It's basically depends on where your session is stored, could also be database, or a file. This only makes sense if your db tables are very denormalized and it requires lots of joins to get the answer. I doubt that's the case so this won't make much difference for the user no matter which data structure used.

大的差异会使得$ P $使用的JavaScript直接进入浏览器的AJAX pfetching他们。在这种情况下,一个简单的阵列就足够了。 JS给你的灵活性,以建立任何性质的任何物体,任何会不够好。所以写在JS轮询器从服务器获取的问题,而用户在看这个问题,使用JSON例如归还。 JSON将成为一个简单的对象。由于每个用户存储的几个问题,只有prefetched在他们的浏览器特定的数据结构的选择会不会在这里做一个差异无论是。

Big difference would make prefetching them with AJAX using javascript straight into the browser. In this case a simple array would suffice. JS gives you flexibility to build any objects with any properties, anything would be good enough. So write a poller in JS which fetches the questions from server while user is looking at the question, return them using JSON for example. JSON will become a simple object. Since each user stores only a couple of questions prefetched in their browser particular data structure choice won't make a difference here either.

这篇关于缓存样的机制(其中数据结构)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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