为缓存最佳解决方案 [英] Best Solution for Caching

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

问题描述

在哪里是要实现一个基于Web的应用程序缓存的最佳地点?

Where is the best place to implement caching in a web based app?


  • 在presentation层(希望不是)?

  • 在业务逻辑层?

  • 在数据层?

我将使用类似的memcached或MS速度引擎盖下。

I'm going to use something like memcached or MS Velocity under the hood.

我只是发现自己写了这么多code在这里和那里的商业逻辑层更新缓存,所以这将是更好地在数据库服务器的高速缓存中的数据访问层之间建立一个布数据?

I'm just finding myself writing so much code to update the cache here and there in the business logic layer, so would it be better to create a fabric in between the data access layer at the Database Server to cache data?

我觉得这些并发症是下降的事实,多数我们缓存中的数据是特定的用户,我们在缓存中的数据复制。我们努力寻找最佳的解决方案。

I think these complications are down to the fact, most of the data we are caching is user specific and we are duplicating data in the cache. We struggling to find the best solution.

推荐答案

Cache是​​一个重要的组成部分或一个Web应用程序,但是,将适合每个项目没有神奇的解决方案。之前您的应用程序的优化工作工作通常是一个坏主意。问自己,你应该实现一个缓存层之前,第一步是要确保您的应用程序运行良好(即使慢)无需任何缓存优化。

Cache is an important part or a web app, but there is no magical solution that will fit every project. Working on optimisations before your app is working is usually a bad idea. Before asking yourself where you should implement a cache layer, the first step is to be sure that your application works well (even if slowly) without any cache optimisation.

在实现这第一步,你就可以开始分析应用程序,列出似乎可以用了大量的资源(可能它是CPU,内存,I / O,数据库访问)或服用了大量的时间特点完成(通常是因为相同的症状)。

When this first step is achieved, you can start profiling the app, listing the features that seem to be using a lot of resources (may it be CPU, memory, i/o, database access) or taking a lot of time to complete (usually because of the same symptoms).

一旦你有,你觉得可以用一个缓存系统进行优化的功能列表中,有两个问题,你需要问自己:

Once you have a list of features that you think can be optimized with a cache system, there are two questions you need to ask yourself :


  • 我怎样才能提高在同一时间所有这些功能(宏焦点):一个明显的答案,这其中往往是数据访问缓存。你通常不希望相同的查询一遍又一遍发送到您的数据库服务器,如果你得到的回报数据始终是相同的。因此,存储在缓存这种类型的数据,有一个聪明的寿命,将永远是一个好主意。

  • "How can I improve all these features at the same time" (macro focus): An obvious answer to this one is often data-access cache. You usually don't want to send the same query to your database server over and over again if the data you get in return is always the same. So storing this type of data in cache, with a clever lifespan, will always be a good idea.

我怎样才能提高每个功能(微焦):这是棘手的,你需要了解你的应用程序很好地弄清楚这一个。一些数据可以被缓存,有些不应该,有的不得。调试器和分析器通常都是伟大的工具,这一步,因为它们有助于你是知道为什么一个特点是缓慢的,并给你有预兆他们应该如何进行优化。

"How can I improve each feature" (micro focus): This is tricky, and you need to understand your application very well to figure this one out. Some data can be cached, some shouldn't, some mustn't. A debugger and a profiler are usually great tools for this step, because they help you being sure why a feature is slow, and give you hints about how they should be optimized.

你要搞清楚的优化可能与您的应用程序(presentation,业务逻辑,数据)的任何一层,但是,这并不意味着你应该实现他们所有。还有,你应该考虑到几个重要的事情:

The optimisations you're going to figure out could be related to any layer of your application (presentation, business logic, data), but that doesn't mean you should implement them all. There are several important things you should take into account:


  • 这是否真的特性需要优化? (它是为客户明显增加?对于硬件?对于整个应用程序?对于其他应用程序吗?)

  • 我能达到什么样的性能? (1%,200%,......)

  • 多少时间将它带我去优化它? (1小时,12天,...)

  • 如何危险的是它优化呢? (可以把它打破东西的应用程序吗?对于客户?)

一旦你拥有了这些问题的答案,它的时间来谈论这个与您的项目经理,与您的同事,甚至与人不与你的应用程序。有中立的意见是很好的,以及具有非技术(或更少的技术)的意见。与这些人交谈应该帮助你找出什么应该做,什么不应该。

Once you have the answers to these questions, it's time to talk about this with your project manager, with your colleagues, or even with people that don't work on the application with you. Having neutral opinion is good, as well as having non-technical (or less technical) opinions. Talking with these people should help you figure out what should be done and what shouldn't.

在这一点上,你应该有最佳化的列表,这是pretty明确,您通过几次想到了,你应该没有问题,编码和测试它们。

At this point you should have a list of optimisations that's pretty clear, that you thought through several times, and you should have no problem coding and testing them.

这篇关于为缓存最佳解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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