I asked this question over at ASP.NET...
http://forums.asp.net/t/1584731.aspx
...but wanted to ask it here as well. I’m sure this problem has been solved before so I figured why reinvent the wheel…
Short story, I’m building a web application with social features using memcached as a caching layer for the database. To simplify the problem, let’s assume a basic setup where we have a persons table and a friendConnection table, where persons contains the personal information and friendConnection has two foreign keys linking one person to another if they have friended one another (I'm not actually using tables or SQL, but the problem is similar)
My cache expiration logic is simple: whenever a put to a table occurs, expire all the select statements related to that table that currently exist in the cache. However that logic is terrible performance-wise because with people friending one another constantly the cache will never last for more than a few seconds.
A more complex logic might, say, expire all the select statements that contain the currently referenced friend, but that would necessitate getting ALL the select statements related to the friendConnection table and checking them for relevance which would also be a performance burden.
Firstly, does my question make sense?
Secondly, how do people solve this problem typically?