knellas wrote:Concoxide, you mention "or rely on caching of the controls content output." Could you please describe in brief how this is done, so that I can try it/
Thanks you in advance,
Well, if your categories always display the same list on every page, you could simply add the following to the top of CategoryNavigation.ascx
<%@ OutputCache Duration="86400" Shared="true" VaryByParam="none" %>
That will cache the output of the control on the server for 86,400 seconds, or 1 day at a time. However, there are some drawbacks to this simple form of caching. If you were to change, add, or delete a category, the pages will not reflect the update until the following day. The first time it is loaded by anyone while that directive is on the control, that is the content that will be loaded for everyone, on every page for the following 24 hours.
There are other ways to do this even better but much more complicated and requires more backend coding and maybe even another table in your database. If you display different categories based on what page you are on, then you would want to cache each different output with its own id using Page.Cache. You could set a dependency so that if you update a category, it would automatically invalidate the cache so a new one could be created. It could take some extensive restructuring of the category navigation control as well as other management areas of the application to make this work well . . but the actual caching and retrieving part would look something like this.
string strCacheID = "myCacheID";
if (Page.Cache.Get(strCacheID) == null)
{
string strCacheDependencyFile = Path.Combine(Request.PhysicalApplicationPath, "myCacheDependency.txt");
string strCacheContent = BuildOutput();
Page.Cache.Add(strCacheID, strCacheContent, new System.Web.Caching.CacheDependency(strCacheDependencyFile), System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.AboveNormal, new System.Web.Caching.CacheItemRemovedCallback(RemoveCallback));
}
divCategories.InnerHtml = Cache.Get(strCacheID).ToString();
with this, you would have a file "myCacheDependency.txt" that could have a 0 or a 1 in it. And whenever you want the cache to reset, switch it in the file. This can be done programmatically, such as in the code where categories are updated. The code also is set to call the subroutine RemoveCallback when the cache is reset, which you will write yourself and you can rebuild the cache within it like so
void RemoveCallback(string tag, object obj, System.Web.Caching.CacheItemRemovedReason reason)
{
string strCacheDependencyFile = Path.Combine(Request.PhysicalApplicationPath, "myCacheDependency.txt");
string strCacheContent = BuildOutput();
Page.Cache.Add(tag, strCacheContent, new System.Web.Caching.CacheDependency(strCacheDependencyFile), System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.AboveNormal, new System.Web.Caching.CacheItemRemovedCallback(RemoveCallback));
}
There is much more that goes into this that i cannot go into in one post. But you should get the picture, get creative :)