コード例 #1
0
        internal T Get <T>(ICacheConsumer consumer, string attribute, Func <T> invokeQuery)
        {
            T t;

            if (this.TryLookupCache <T>(consumer, attribute, out t))
            {
                return(t);
            }
            T result;

            lock (this.GetConcurrencyLock(attribute))
            {
                if (this.TryLookupCache <T>(consumer, attribute, out t))
                {
                    result = t;
                }
                else
                {
                    t = StorageGlobals.ProtectedADCall <T>(invokeQuery);
                    this.cacheLock.EnterWriteLock();
                    try
                    {
                        OrganizationCache.MiniPropertyBag miniPropertyBag;
                        if (!this.cache.TryGetValue(consumer.Id, out miniPropertyBag))
                        {
                            miniPropertyBag         = new OrganizationCache.MiniPropertyBag();
                            this.cache[consumer.Id] = miniPropertyBag;
                        }
                        miniPropertyBag[attribute] = t;
                        result = t;
                    }
                    finally
                    {
                        this.cacheLock.ExitWriteLock();
                    }
                }
            }
            return(result);
        }
コード例 #2
0
 internal bool TryLookupCache <T>(ICacheConsumer consumer, string attribute, out T result)
 {
     try
     {
         this.cacheLock.EnterReadLock();
         OrganizationCache.MiniPropertyBag miniPropertyBag;
         if (this.cache.TryGetValue(consumer.Id, out miniPropertyBag) && miniPropertyBag.TryGet <T>(attribute, out result))
         {
             return(true);
         }
     }
     finally
     {
         try
         {
             this.cacheLock.ExitReadLock();
         }
         catch (SynchronizationLockException)
         {
         }
     }
     result = default(T);
     return(false);
 }