Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

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 12:03 PM
 

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/18/2008 12:37 AM
 

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 4: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;
        }


Entrepreneur

PokerDIY Tournament Manager - PokerDIY Tournament Manager<
PokerDIY Game Finder - Mobile Apps powered by DNN
PokerDIY - Connecting Poker Players

 
New Post
8/18/2008 7: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 4:06 AM
 

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


Entrepreneur

PokerDIY Tournament Manager - PokerDIY Tournament Manager<
PokerDIY Game Finder - Mobile Apps powered by DNN
PokerDIY - Connecting Poker Players

 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Implementing chace in my own modules?Implementing chace in my own modules?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, 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 DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out