Reputation: 38638
We have a social network inside our system and we have implemented a timeline to show users what they can see (posts from other users and communities that he belongs). Given we have some linq-to-sql
queries hitting on the database it works fine and the users can perform actions such as comments on the posts and like the posts. We also have an interval timer on the javascript that request some updates to the timeline (to users see the new posts etc.). The timeline is made as infinite scrolling loading 10 by 10 (according what users can see).
We want to improve the performance of this method and we were thinking about how to cache the timeline. The main problem is that we have a lot of posts
(more than 10000 with comments and likes) and to cache the entire post
table is not a good idea. We have tested it and get a bad performance because our cache get a huge size and slow to process pages with linq (in memory).
Is there any idea how can we load the cache by demand and user based? Or is there other alternatives.
We can use Redis or .Net MemoryCache implementation.
Thank you.
Upvotes: 1
Views: 264
Reputation: 101192
No one will scroll through the entire history, no need to load everything into a cache.
Each time a user requests a new page, load it if it's not in the cache and also load the next 10 items into the cache. That way the first request is the only one that might will be slow for every user.
Also set an expiration date on each page, remove it from the cache if no one have requested it in X time units.
Do note that pages have to be reordered when new items have been created (the oldest entry in the first page have to be moved to the second page etc). (or just keep everything in a single list, but use a list implementation that doesn't force items to be moved when something is inserted at position 0)
Upvotes: 1