HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Implementing chace in my own modules?Implementing chace in my own modules?
Previous
 
Next
New Post
8/17/2008 10:03 AM
 

Hi All

I'd like to implement cache in my own modules but going throught the Html module source code I am not really able to pinpoint where this is being done ... anyone can give me a hint on where to look in the source code or to do somethingelse with my modules? I did go through the sourcecode by setting several breaking points in the code and walk through it but couldn't find it ...

/Johan

Lagerbolag

 
New Post
8/17/2008 10:37 PM
 

Ok, it turns out to be that cache is native in every module you make in DotNetNuke! ... i just gave my module dome default values in the module settings in the host menu .... interesting ... but I don't see any sharp heavy performance kick in but then again the system is not very loaded right now.....

/Johan

 
New Post
8/18/2008 2:11 AM
 

Here is how I use caching in the ST modules:

 

        public UserInfo GetUserFromCacheOrDB(int portalID, int userID, int profileCacheSeconds)
        {
            //check if caching must be used - check if this user record is in the cache, and use it
            string cacheKey = portalID.ToString() + "UserID" + userID.ToString();
            UserInfo user;

            bool userInCache = (DataCache.GetCache(cacheKey) != null);

            if (profileCacheSeconds > 0 && userInCache)
            {
                user = (UserInfo)DataCache.GetCache(cacheKey);
            }
            else
            {
                //get it from the DB
                user = new UserController().GetUser(portalID, userID);

                if (user != null && profileCacheSeconds > 0 && !userInCache)
                {
                    //add it to the cache with an absoulte expiry time (otherwise it may never update)
                    DataCache.SetCache(cacheKey, user, DateTime.Now.AddSeconds(profileCacheSeconds));
                }
            }
            return user;
        }


Thanks,
Rodney
Smart-Thinker - Home of SmartSocial - the 100% Free DotNetNuke Social Networking Product Suite
Do use DNN a lot? Try the DotNetNuke Toolbar to save you time!
PokerDIY - Example Implementation of DNN Social Network
 
New Post
8/18/2008 5:35 PM
 

Rodney

If I can just throw my 2 cents in here, there's a slight bug in your code there.

The problem is you're checking the cache twice, so you introduce the possibility of a null reference error, depending on when the system flushes the cache.  This normally happens in high-load situations, which increases the chances the cache will be flushed between the two steps:

Your code:

            bool userInCache = (DataCache.GetCache(cacheKey) != null);

            if (profileCacheSeconds > 0 && userInCache)
            {
                user = (UserInfo)DataCache.GetCache(cacheKey);

            }

            else
            {
                //get it from the DB

Should be:

            UserInfo user = (UserInfo)DataCache.GetCache(cacheKey);

            if (user == null)
            {
                //get it from the DB

Doing it this way means you're only pulling from the cache once, so you eliminate the possibility that it is there when the first check runs, and missing when the second check runs.  It's a minor issue but one worth noting.

-Bruce  

 
New Post
8/20/2008 2:06 AM
 

Thanks for pointing that out Bruce, I didn't think of that!


Thanks,
Rodney
Smart-Thinker - Home of SmartSocial - the 100% Free DotNetNuke Social Networking Product Suite
Do use DNN a lot? Try the DotNetNuke Toolbar to save you time!
PokerDIY - Example Implementation of DNN Social Network
 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Implementing chace in my own modules?Implementing chace in my own modules?


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, please observe the following posting guidelines:

1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

Attend A Webinar
Try An Online Demo
Download DotNetNuke Professional Edition Trial
Have Someone Contact Me

Like Us on Facebook Join our Network on LinkedIn Follow DNN Corporate on Twitter Follow DNN on Twitter

Advertisers

DotNetNuke Scoop!

Sponsors

DotNetNuke Corporation

DotNetNuke Corp. is the steward of the DotNetNuke open source project, the most widely adopted Web Content Management Platform for building web sites and web applications on Microsoft .NET. Organizations use DotNetNuke to quickly develop and deploy interactive and dynamic web sites, intranets, extranets and web applications. The DotNetNuke platform is available in a free Community and subscription-based Professional and Enterprise Editions with an Elite Support option. DotNetNuke Corp. also operates Snowcovered.com where users purchase third party apps for the platform.