I have always worked on projects where caching was done on DAL, basically just w
ID: 645920 • Letter: I
Question
I have always worked on projects where caching was done on DAL, basically just when you are about to make the call to database, it checks if data is already there in the cache and if it is, it just doesn't make the call and instead returns that data.
I just recently read about caching at business layer, so basically caching the entire business objects. One advantage I can see straight away is much better response times.
When would you prefer one over the other? and Is caching at Business Layer a common practice?
Explanation / Answer
This is probably too broad for a definitive answer. Personally, I feel that a data access layer is the better place for caching, simply because it is supposed to be very simple - records go in and out and that's it.
A business layer implements many additional rules of higher complexity, so it's better if it doesn't alsohave to manage per-object availability concerns in addition to multiple-object consistency concerns in the same class(or even the same method) - that would be a blatant violation of the SRP.
(Of course, I only reached that insight after my service classes had grown to unmanageable complexity when they tried to do both caching and configuration simultaneously. There is no better teacher than experience, but the price sure is steep.)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.