views:

69

answers:

2

We are using Smarty Templates on our LAMP site but my question would also apply to a site running Memcached (which we are planning to also bring online). Many of the pages of our user generated site have different views depending on who is looking at them. For instance, a list of comments where your own comments are highlighted. There would need to be a unique cache-id for each logged in user for this specific view. My question is, in this scenario, would you not even cache these views? Or is the overhead in creating/using the cache (either for smarty or memcached), low enough that you still would see some benefit to the cache?

+1  A: 

Unless individual users are requesting the pages over and over again, there's no point caching this sort of thing, and I expect the overhead of caching will vastly exceed the performance benefits, simply since the cache hit ratio will be poor.

You may be better off looking into caching fragments of your site that do not depend on the individual user, or fragments that will be the same for a large number of page impressions (e.g. content that is the same for a large subset of your users).

For example - on this page you might want to cache the list of related questions, or the tag information, but there's probably little point caching the top-bar with reputation info too aggressively, since it will be requested relatively infrequently.

Dominic Rodger
In my comments example, I think we won't be able to use smarty's cache but with Memcached we'll break our query into two parts. The first will be a select of all the comments for the given piece of content. That we will cache (using memcached). Then we'll iterate through those results and get whether the post is by the logged in user. The product of that we won't cache.
weotch
A: 

If the view code isn't too complicated just cache the data and generate the view each time.

Pomyk