Whenever a statistics query is made, cache it into some kind of in-memory storage. Whenever an insertion of a new reaction is made, clear the cache.