I have a DAL which is used to persist a large number of time-series measurements into a RDBMS database (MS SQL Server). There is also a web app which connects to this database and displays trends online (usually charts several months of data, with, say, 5-min min/max/average aggregates for various quantities and IoT devices).
Due to the amount of data, I would like to cache the aggregated results into a separate table, and it would be also pretty cool if I could have an additional layer of in-memory caching. However, devices often send historical data with older timestamps, meaning that the cache often needs to be invalidated, and there are two apps which access this data (the service which inserts/updates and occasionally reads the data, and the web application which reads the data).
I have looked into several options, like SQL triggers, or simply invalidating the table manually, but I am not sure how to propagate the cache invalidation to the web app properly.
Is there a way to somehow detect SQL events in my web app and invalidate cache? Or have a separate process for in-memory cache, which can also be invalidated? Or should I perhaps create my own third service which would be a proxy for all db operations, providing an in-memory cache of the data (this sure seems like an overkill)?