If you need caching in your website to make database use lower, do you have to do it using memcache or memcached (in PHP, for example) or can you achieve this by using professional services like CloudFlare, Incapsula or others like that do some caching for you?
-
1There are many different forms of caching. memcached is a different form of caching with different use cases than services like Cloudflare. What exactly is your goal for caching? – deceze Dec 15 '11 at 04:05
-
Well, I'm not sure if there are other uses to it than reducing database queries (specially those that are repeated many times in small time lapses). Just overall speeding of the site – federico-t Dec 15 '11 at 04:08
-
1First step is to identify which parts of the site are slow. Then different caching models can be looked at -- or perhaps just cleaning up a grossly inefficient query or incorrect caching? -- in relationship to the issue and how they can be applied – Dec 15 '11 at 04:15
2 Answers
Services like Cloudflare cache your HTML and/or assets like images and CSS files in a CDN, so that your entire server is hit less often. This is great for semi-static sites but may not be the best fit for highly dynamic sites.
Local caches like memcached just store any data in a way that's fast to access. You can use that to cache database queries and lower your database activity, but you can also use it to store pre-computed data that would be expensive to re-create all the time or whatever else you may want to store non-permanently in a fast-to-access way.
Both solutions solve different problems. You may use both together, or either, or neither. It really depends on where exactly your bottleneck is and which solution fits your problem better.

- 510,633
- 85
- 743
- 889
-
Interesting answer. So, would you advice to use services like Cloudflare with dynamic web apps just for static files or to not use it at all? Maybe using Cloudflare to cache the CSS and javascript files and local cache for the dynamic interaction with the database and repeated information retrieval would be the best option – federico-t Dec 15 '11 at 04:40
-
Sure, sounds great. I have no direct experience with Cloudflare, so I can't say how well it works for dynamic content or how customizable it is, but I'm sure you can use some of their services to your advantage. – deceze Dec 15 '11 at 04:45
I'm the CEO of CloudFlare and I'd say: more (intelligent) caching is almost always a good thing. While we can significantly decrease the load coming to your web server, to get the best performance it's still extremely important to optimize your web application and it's interaction with your database. To that end, memcache and other fast caching layers can play an important role and I'd never discourage them.
PS - we work great with dynamic sites. 95%+ of our sites are highly dynamic web applications.

- 31
- 1