Module Helper like CacheHelper

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
3/13/2012 9:29:07 AM
Gravatar
Total Posts 88

Module Helper like CacheHelper

Hi,

Im creating an object like CacheHelper to create several functions to return some constant data from object that are manipuled on my own modules with HttpContext.Current.Items["Key"]. But when page change they lost data i´ve created and all data like sitesettings and other in cacheHelper.cs doesnt lost. Any reason for that?

thanks

3/13/2012 9:42:51 AM
Gravatar
Total Posts 18439

Re: Module Helper like CacheHelper

Right, HttpContext.Items is just a place to store things for the lifetime of the current request and is faster than acccessing items from cache so we use it for things that might get looked up in multiple places in code or controls during a given request so that the first time it is looked up either from the db or from cache it is then stored in Context.Items and the next thing that wants to access it gets it from there so we never lookup the object from the db or cache more than once during a given web page request.

ie SiteUtils.GetCurrentUser may be called in a bunch of places in code during a request but the first time it is stored in Context.Items so we don't hit the db for it more than once during a request.

SiteSettings is similar but it is a little more expensive object and also used even more frequently so we cache it for about 5 minutes at a time, but the first time we get it from cache we keep it in Context.Items because it will be used lots of places during a given request and accessing Context.Items is much faster than accessing the cache over and over during the request.

Caching uses server memory which is usually a very precious resource so you don't want to go hog wild caching things, ie we don't cache SiteUser because with a lot of users that would gobble up memory. If memory usage reaches limits set on the app pool it causes the app to recycle frequently which hurts performance.

Hope that helps,

Joe

3/13/2012 1:15:57 PM
Gravatar
Total Posts 88

Re: Module Helper like CacheHelper

 

Ok, i know this things, but i can´t understand why sitesettings is always avaliable and my httpContext.items["ModuleObject"]

that i create when the user starts the module page, isn´t availiable when user changes to other page on the same module.

Thanks

3/13/2012 1:22:07 PM
Gravatar
Total Posts 18439

Re: Module Helper like CacheHelper

I told you HttpContext.Items does not persist across pages.

SiteSettings is stored in cache and added back to HttpContext.Items on every request the first time any code tries to access it from CacheHelper.GetCurrentSiteSettings()

The very first time that code is called during a request it looks in HttpContext.Items if it is not there it gets it from cache and puts it there, then any other code during that request when it calls CacheHelper.GetCurrentSiteSettings() it does exist in HttpContext.Items because the first call put it there.

3/13/2012 1:39:46 PM
Gravatar
Total Posts 88

Re: Module Helper like CacheHelper

Ok, thanks a lot.

You must sign in to post in the forums. This thread is closed to new posts.