Using Python's Django (w/ Rest framework) to create an application similar to Twitter or Instagram.
What's the best way to deal with caching content (JSON data, images, etc.) considering the constantly changing nature of a social network? How to still show updated state a user creates a new post, likes/comments on a post, or deletes a post while still caching the content for speedy performance?
If the cache is to be flushed/recreated each time a user takes an action, then it's not worth having a cache because the frequency of updates will be too rapid to make the cache useful. What are some techniques of dealing with this problem.
Please feel free to share your approach and some wisdom you learned while implementing your solution. Any suggestions would be greatly appreciated. :)
One technique is to key the URLs on the content of the media they are referring too.  For example if you're hosting images then use the sha hash of the image file in the url /images/<sha>.
You can then set far-future cache expiry headers on those URLs.  If the image changes then you also update the URL referring to it, and a request is made for an image that is no longer cached.
You can use this technique for regular database models as well as images and other media, so long as you recompute the hash of the object whenever any of its fields change.
Handling Cache with Constant Change of Social Network