I need to implement cache for SQL queries. Say we have "SELECT id,aa,bb FROM table1 WHERE aa>1 and bb=12;" -- we want it to be cached. Also, it may be "SELECT id,aa,bb FROM table1 WHERE aa>25 and bb=11;" And can be "SELECT id,aa,bb FROM table2;" of course.
Not a big deal -- what really is a question is how to expire cache values better. On updates. Say, we added new row with "INSERT .." or updated existing data with "UPDATE ...". We need to expire all cache which had SELECTs values, as they may not be accurate any more.
How to do this better?
In the simplest case -- we use the whole "SQL query" ask key in the cache. But at the moment of INSERT/UPDATE we have no idea which queries to expire (which keys?)