I have a question regarding Caching. I have a typical n-tier ASP.NET web app. I have made a custom Cache wrapper (wrapping ASP.NET Cache object), and I would like to know the best practices of Caching data. I don't want to use caching in my business layer (don't want to add any reference to System.Web dll there). Same case with DAL. So the only options left are:
I also heard about the upcoming Velocity caching framework but I guess that might be an overkill (as my app wont need a web farm/cluster).
I may be terribly wrong in my approaches, so I would welcome any suggestions or alternative approaches on how to effiecintly cache data in my web projects.
The layer between your UI and BLL would be a Services layer, which is a good place for caching. Use an abstracted cache manager (example on my blog) so you can swap out providers (ASP.NET cache, Velocity, memcached, whatever) when needed.
Sometimes it's also worth considering what the purpose of the cached data is for? If it's ultimately just going to generate static HTML in the UI layer than wrapping these parts in a user control and adding an @OutputCache directive can be the most efficient way (when using web forms, at least). It's easy to forget this, sometimes, when you get bogged down in caching frameworks etc. Of course I appreciate this may not be suitable or best-practise in many cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With