Reputation: 963
We've currently got a website with a large amount of comments (with "upvote" scores) that are always sorted by id and not paginated.
We wanted to add in different ways to sort the comments (newest, top score, etc) as well as pagination which can be customize (10, 25, 100 per page).
Right now, caching for us is easy. We can memcache the raw HTML and just spit out the comments for an object. If we cache every possible combination of per_page and sort_method than we can achieve this, but hits will be much less common since their is much more specificity.
We're currently trying to think of a good strategy for this, but we're a little stumped.
Extra info:
Upvotes: 2
Views: 897
Reputation: 1865
I don't think that there is only one answer to this as a lot depends on the actual numbers of your website, for example the maximum number of comments per id.
However I would not cache the HTML pages but rather the data that was required to construct the pages, possibly as an SQL resultset. I would have one cache entry for each sort order with all of the comments and then just filter out the ones you do not need. If that seems too big then you could also go down the route of partitioning it into chunks of N comments.
Remember that you will need to have some robust method of dealing with updates, so knowing which keys to delete is important, which is why I like the above solution with all of the comments, but as I said it really depends on your numbers.
Upvotes: 1