简单页面的基本缓存策略? [英] Basic caching strategy for a simple page?

查看:97
本文介绍了简单页面的基本缓存策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用memcache和app引擎(java)。我有一个页面,可以缓存从数据存储中获取的结果。例如:

  // index.jsp 
<%
List< Horse> horses = datastore.getHorses(PMF.get());

(马匹:马){
%>
< div><%= it.getName()%>< / div>
<%
}
%>

我可以将马列表放到memcache中,但是将整个页面缓存起来会更有意义内容?我的意思是下一次用户想要加载这个页面,只是将储存在缓存中的整个html内容作为一个字符串吐出来?想知道这是可能的还是一个好的做法。我不知道我该怎么做,因为我需要创建一个大量的所有html内容的字符串,然后在jsp中打印()它,并将它存储在memcache中,如下所示:

  // index.jsp 
<%
List< Horse> horses = datastore.getHorses(PMF.get());

StringBuilder sb = new StringBuilder();
for(Horse it:horses){
sb.append(< div>);
sb.append(it.getName());
sb.append(< / div>);
}

//渲染内容。
<%= sb.toString()%>

//也可以将它存储在memcache中以备将来使用。
memCache.put(test / index.jsp,sb.toString());
%>

谢谢

解决方案如果你不需要马列表来完成其他任何事情,并且你的页面不是用户特定的,那么缓存整个页面应该会更快。否则,缓存马名单。



缓存马名单将需要序列化和反序列化列表。这也可能会缓存您不关心的信息(即,未在您的网页上使用的信息)。另一方面,您的HTML页面只是文本,因此序列化/反序列化几乎是不可操作的。


I'm starting to work with memcache and app engine (java). I have a page where I can cache results fetched from the datastore. Example:

// index.jsp
<%
List<Horse> horses = datastore.getHorses(PMF.get());

for (Horse it : horses) {
    %>
    <div><%= it.getName() %></div>
    <%
}
%>

I can put the horse list into memcache, but would it make more sense to just cache the entire page contents? I mean next time the user wants to load this page, just spit back the entire html content stored in the cache as a string? Wondering if that's possible or a good practice. I'm not sure how I would do this anyway, since I would need to create one massive string of all the html content, then print() it in the jsp, and also store it in memcache, something like:

// index.jsp
<%
List<Horse> horses = datastore.getHorses(PMF.get());

StringBuilder sb = new StringBuilder();
for (Horse it : horses) {
    sb.append("<div>");
    sb.append(it.getName());
    sb.append("</div>");
}

// Render contents.
<%= sb.toString() %>

// Also can store it in memcache for future requests.
memCache.put("test/index.jsp", sb.toString());
%>

Thanks

解决方案

If you don't need the horse list for anything else and your page isn't user-specific, then it should be faster to just cache the whole page. Otherwise, cache the horse list.

Caching the horse list will require serializing and deserializing the list. This might also cache information you don't care about (i.e., information not used on your page). On the other hand, your HTML page is just text and so serializing/deserializing it is almost a no-op.

这篇关于简单页面的基本缓存策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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