当前位置: 首页>>代码示例>>C#>>正文


C# CacheEntry.ReleaseLock方法代码示例

本文整理汇总了C#中CacheEntry.ReleaseLock方法的典型用法代码示例。如果您正苦于以下问题:C# CacheEntry.ReleaseLock方法的具体用法?C# CacheEntry.ReleaseLock怎么用?C# CacheEntry.ReleaseLock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CacheEntry的用法示例。


在下文中一共展示了CacheEntry.ReleaseLock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Insert

        /// <summary>
        /// Adds a pair of key and value to the cache. If the specified key already exists 
        /// in the cache; it is updated, otherwise a new item is added to the cache.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="cacheEntry">the cache entry.</param>
        /// <returns>returns the result of operation.</returns>
        public sealed override CacheInsResultWithEntry Insert(object key, CacheEntry cacheEntry, bool notify, bool isUserOperation, object lockId, LockAccessType access, OperationContext operationContext)
        {
            CacheInsResultWithEntry result = new CacheInsResultWithEntry();
            try
            {
                CacheEntry pe = null;
                CallbackEntry cbEtnry = null;
                OperationID opId = operationContext.OperatoinID;
                EventId eventId = null;
                EventContext eventContext = null;
                
                pe = GetInternal(key, false, operationContext);
                result.Entry = pe;

                if (pe != null && access != LockAccessType.IGNORE_LOCK)
                {
                    {
                        if (access == LockAccessType.RELEASE || access == LockAccessType.DONT_RELEASE)
                        {
                            if (pe.IsItemLocked() && !pe.CompareLock(lockId))
                            {
                                result.Result = CacheInsResult.ItemLocked;
                                result.Entry = null;
                                return result;
                            }
                        }
                        if (access == LockAccessType.DONT_RELEASE)
                        {
                            cacheEntry.CopyLock(pe.LockId, pe.LockDate, pe.LockExpiration);
                        }
                        else
                        {
                            cacheEntry.ReleaseLock();
                        }
                    }
                }
                ExpirationHint peExh = pe == null ? null : pe.ExpirationHint;

                if (pe != null && pe.Value is CallbackEntry)
                {
                    cbEtnry = pe.Value as CallbackEntry;
                    cacheEntry = CacheHelper.MergeEntries(pe, cacheEntry);
                }
                result.Result = InsertInternal(key, cacheEntry, isUserOperation, pe, operationContext);

                if ((result.Result == CacheInsResult.Success || result.Result == CacheInsResult.SuccessNearEvicition) && _stateTransferKeyList != null &&
                    _stateTransferKeyList.ContainsKey(key))
                {
                    result.Result = result.Result == CacheInsResult.Success ? CacheInsResult.SuccessOverwrite : CacheInsResult.SuccessOverwriteNearEviction;
                }
                // Not enough space, evict and try again.
                if (result.Result == CacheInsResult.NeedsEviction || result.Result == CacheInsResult.SuccessNearEvicition
                    || result.Result == CacheInsResult.SuccessOverwriteNearEviction)
                {
                    Evict();
                    if (result.Result == CacheInsResult.SuccessNearEvicition) result.Result = CacheInsResult.Success;
                    if (result.Result == CacheInsResult.SuccessOverwriteNearEviction) result.Result = CacheInsResult.SuccessOverwrite;
                }

                // Operation completed!
                if (result.Result == CacheInsResult.Success || result.Result == CacheInsResult.SuccessOverwrite)
                {
                    // commented by muds
                    //remove the old hint from expiry index.
                    if (peExh != null)
                        _context.ExpiryMgr.RemoveFromIndex(key);

                    if (cacheEntry.ExpirationHint != null)
                    {
                        cacheEntry.ExpirationHint.CacheKey = (string)key;
                        if (isUserOperation)
                        {
                            try
                            {
                                _context.ExpiryMgr.ResetHint(peExh, cacheEntry.ExpirationHint);
                            }
                            catch (Exception e)
                            {
                                RemoveInternal(key, ItemRemoveReason.Removed, false, operationContext);
                                throw e;
                            }
                        }
                        else
                        {
                            cacheEntry.ExpirationHint.ReInitializeHint(Context);
                        }

                        _context.ExpiryMgr.UpdateIndex(key, cacheEntry);
                    }
                    if (IsSelfInternal)
                    {
                        _context.PerfStatsColl.IncrementCountStats((long)Count);
                    }
//.........这里部分代码省略.........
开发者ID:christrotter,项目名称:NCache,代码行数:101,代码来源:LocalCacheBase.cs


注:本文中的CacheEntry.ReleaseLock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。