I am working on a project that allows a user to scroll through posts in a page , ex: like facebook. They can scroll through the older posts.
Ex: Say multiple users visit a particular timeline and scroll through their pages. The posts from the timeline are stored in a database and when the user requests for a particular page, those posts are loaded into the memory.
Ex: DynamoDB offer paginated query and loading.
I am trying to find out how caching paginated results can be optimized. One solution is to load the posts using a time-range fashion ex: 5/10/15 minutes and store it in the cache. All the posts from 10:00-10:05AM/10:05-10:10AM will be loaded.
Ex: A user scrolls through the pages and requests for posts within the time-period 10:00-10:05 AM from the cache. Next time, when a different user wants to view the same posts, then the user can query the cache with exact "key-start time" combination : ex : "testKey-10:00". THis entry in the cache would hold all the posts for the key "testKey" and within the time range 10:00-10:05AM if the time slice interval is 5 minutes.
So, the cache will contains keys namely "testKey-10:00", "testKey-10:05" etc.
Inorder to calculate a good time-interval, I should know the traffic pattern and the no.of hits/sec. But, if the no.of hits keeps changing going high and low, memory may can contain too many posts at a single instant.
I am looking for any opinion/feedback or any alternate approaches for caching paginated data.
I use DynamoDB as a database and Redis for caching.
Aucun commentaire:
Enregistrer un commentaire