DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 22 Aug 2007 09:09:37 -0400,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Showjumper nlsdkfja
          2    Eliyahu Goldin
          3    sloan
          4    Showjumper nlsdkfja
          5    Paul
          6    Paul


Caching business objects?   
Hi
I have custom bustom objects whose properties i populate using a datareader. 
Is it possible to cache the business object afteri have populated it? If so, 
how? Everything i have tried does not work.

Ashok
Date:Wed, 22 Aug 2007 09:09:37 -0400   Author:  

Re: Caching business objects?   
Did you try putting it into a session variable?

-- 
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"Showjumper" <nlsdkfja> wrote in message 
news:etdFy2L5HHA.4712@TK2MSFTNGP04.phx.gbl...

> Hi
> I have custom bustom objects whose properties i populate using a 
> datareader. Is it possible to cache the business object afteri have 
> populated it? If so, how? Everything i have tried does not work.
>
> Ashok
>
> 
Date:Wed, 22 Aug 2007 16:34:59 +0300   Author:  

Re: Caching business objects?   
When I know I need to cache these objects, I usually go ahead an put on the
[Serializable]
attribute.

This would affect you if you ever went to Session storing like sql server 
session state.


You can also look at this fancy object I wrote, for a "strong typed" version 
of storing items in Session.

http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!151.entry


If you're on 1.1, go back to the main blog page, there is a 1.1 version of 
it as well.





"Showjumper" <nlsdkfja> wrote in message 
news:etdFy2L5HHA.4712@TK2MSFTNGP04.phx.gbl...

> Hi
> I have custom bustom objects whose properties i populate using a 
> datareader. Is it possible to cache the business object afteri have 
> populated it? If so, how? Everything i have tried does not work.
>
> Ashok
>
> 
Date:Wed, 22 Aug 2007 10:08:24 -0400   Author:  

Re: Caching business objects?   
No i did not try session variables. I was attempting to use cache.insert
"Showjumper" <nlsdkfja> wrote in message 
news:etdFy2L5HHA.4712@TK2MSFTNGP04.phx.gbl...

> Hi
> I have custom bustom objects whose properties i populate using a 
> datareader. Is it possible to cache the business object afteri have 
> populated it? If so, how? Everything i have tried does not work.
>
> Ashok
>
>
> 
Date:Wed, 22 Aug 2007 20:15:42 -0400   Author:  

Re: Caching business objects?   
Here is what we use ( in a static class )
Be aware that Cache is global and NOT session based.

        #region checkCache
        /// <summary>
        /// Will test for the requested value in the Session Cache.
        /// </summary>
        /// <typeparam name="T">Type of cached object</typeparam>
        /// <param name="sKey">Key to search on</param>
        /// <returns>T</returns>
        public static T checkCache<T>(string sKey)
        {
            T returnValue = default(T);

            if (HttpContext.Current != null)
            {
                object oValue = HttpContext.Current.Cache.Get(sKey);

                if (oValue is T)
                {
                    returnValue = (T)oValue;
                }
            }

            return returnValue;
        }
        #endregion

        #region cacheItem
        /// <summary>
        /// Cache items to the session chache for a set number of
minutes.
        /// </summary>
        /// <param name="sKey"></param>
        /// <param name="oItem"></param>
        /// <param name="cacheMinutes"></param>
        public static void cacheItem(string sKey, object oItem, int
cacheMinutes)
        {
            if (HttpContext.Current != null && oItem != null)
            {
                Cache cache = HttpContext.Current.Cache;

                object oExistingItem = cache.Get(sKey);

                // If the item is already cached
                if (oExistingItem != null)
                {
                    cache.Remove(sKey);
                }

                cache.Add(sKey, oItem, null,
DateTime.Now.AddMinutes(cacheMinutes), Cache.NoSlidingExpiration,
CacheItemPriority.Normal, null);

            }
        }
        #endregion

        #region expireCacheItem
        /// <summary>
        /// Removes an item from the Cache.
        /// </summary>
        /// <param name="sKey"></param>
        public static void expireCacheItem(string sKey)
        {
            if (HttpContext.Current != null)
            {
                HttpContext.Current.Cache.Remove(sKey);
            }
        }
        #endregion
Date:Thu, 23 Aug 2007 04:59:56 -0700   Author:  

Re: Caching business objects?   
An example of calling that code using the Session ID to make is
session specific in this case.

                string sCacheKey = "CMSContext{0}{1}";
                sCacheKey = string.Format(sCacheKey,
loggedOnUser.GUID, Session.SessionID);

                CMSContext currentContext =
util.checkCache<CMSContext>(sCacheKey);

                if (currentContext == null)
                {
                    currentContext = new CMSContext(Session,
loggedOnUser);
                }

                // Unlike most cache Items we refresh the Cache of
this Item every time it is accessed
                util.cacheItem(sCacheKey, currentContext, 20);
Date:Thu, 23 Aug 2007 05:00:42 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us