Friday, February 20, 2009

DotNetNuke - Clearing cache dynamically or programmaticaly

Perfomance is a key requirement for every application, and so does it is for DotNetNuke web applications also. DotNetnuke uses data caching as an inbuilt approach and provides a provider for cache also. It always adds good perfomance gain by setting the proper cache value and cache policy to you dotnetnuke web application. But there are times when you need to clear the cache of the application. If you are a host or admin and you want to manage it from the from end, you can go to :
Host - Host Settings - Advance Settings - Perfomance Settings
You can find a clear cache button there which will help you clearing cache. But there are times when this is not logical. For intance if you are allowing a user to choose a new skin from the list, when user clicks and applies a new skin, at that time you have to clear the cache manually, otherwise changes will not reflect properly.

DotNetNuke.Common.Utilities.DataCache is a class which will help you clearing cache at various occations like I discussed above. In our scenerio, we have to clear portal cache and we can do that by calling
DotNetNuke.Common.Utilities.DataCache.ClearPortalCache(PortalId, false);
And its as simple as that. There are lots of other functions to clear cache starting from clear, like ClearModuleCache or ClearModulePermissionCache. You can use them as and when required.
Hope that helps

No comments:

Post a Comment

Please add your valuable comments about this post if it helped you. Thanks