I'm adding Redis to our Spring project and want to determine a suitable caching strategy. I am considering caching the result at the Controller's endpoint/method level for GET requests and invalidating the cache on the Controller's for POST/PUT requests. However, this doesn't seem to be a perfect solution as we don't always have enough information at the controller level to know what to invalidate. So, alternatively, I am considering invalidating the cache whenever we save to the database since there are limited areas where we would need to add cache invalidation rules.
Is it best to cache in the Controllers or at costly methods the Service layer may call? When invalidating the cache, is it a good design pattern to invalidate at the controller level or as we are updating the DB?