I have a web application with an express/node backend using typeorm and PostgreSQL. The home page in my app is a query with lots of inner joins that shows the user a complex report. This query takes about 30 seconds to run which is a bad experience.
I could easily add caching with a ttl value, but that has 2 problems. First the report could be out of date if the user hits the cache after updating data. Second the first page load after the ttl expires will be slow.
Since the report only changes when more records are added to the database I could use the number of records as a key to tell me whether the cache value is out of date or not, solving the first problem. And then I could have a queued process that updates the cache in the background any time the number of records in the database changes, solving the second problem.
The only thing is, I don’t know if any third party libraries exist that already do this or if I’m somehow reinventing existing functionality. Does this strategy have a name?