public static ExpirationHint GetExpirationHintObj(PoolManager poolManager, Alachisoft.NCache.Common.Protobuf.Dependency dependency, long absoluteExpiration, long slidingExpiration, bool resyncOnExpiration, string serializationContext) { ExpirationHint hint = null; //We expect Web.Cache to send in UTC DateTime, AbsoluteExpiration is dealt in UTC if (absoluteExpiration != Common.Util.Time.MaxUniversalTicks && absoluteExpiration != 0 && absoluteExpiration != 1 && absoluteExpiration != 2) { hint = FixedExpiration.Create(poolManager, new DateTime(absoluteExpiration, DateTimeKind.Utc)); } if (slidingExpiration != 0 && slidingExpiration != 1 && slidingExpiration != 2) { hint = IdleExpiration.Create(poolManager, new TimeSpan(slidingExpiration)); } ExpirationHint depHint = GetExpirationHintObj(poolManager, dependency, false, serializationContext); if (depHint != null) { if (hint != null) { if (depHint is AggregateExpirationHint) { ((AggregateExpirationHint)depHint).Add(hint); hint = depHint; } else { hint = AggregateExpirationHint.Create(poolManager, hint, depHint); } } else { hint = depHint; } } if (hint != null && resyncOnExpiration) { hint.SetBit(ExpirationHint.NEEDS_RESYNC); } return(hint); }
/// <summary> /// Recupera uma entrada do cache. /// </summary> /// <param name="key"></param> /// <param name="item"></param> /// <param name="flag"></param> /// <param name="group"></param> /// <param name="subGroup"></param> /// <param name="cacheEntry"></param> /// <returns></returns> public UserBinaryObject GetCacheEntry(string key, ProviderCacheItem item, ref BitSet flag, string group, string subGroup, out CacheEntry cacheEntry) { UserBinaryObject val = null; cacheEntry = null; object serializableObject = null; if ((item != null) && (item.Value != null)) { if ((item.Group == null) && (item.SubGroup != null)) { throw new OperationFailedException("Error occurred while synchronization with data source; group must be specified for sub group"); } if ((group != null) && !CacheHelper.CheckDataGroupsCompatibility(new GroupInfo(item.Group, item.SubGroup), new GroupInfo(group, subGroup))) { throw new OperationFailedException("Error occurred while synchronization with data source; groups are incompatible"); } if (flag == null) { flag = new BitSet(); } serializableObject = item.Value; Hashtable hashtable = new Hashtable(); TypeInfoMap typeInfoMap = _context.CacheRoot.GetTypeInfoMap(); hashtable["query-info"] = CacheLoaderUtil.GetQueryInfo(item.Value, typeInfoMap); if (item.Tags != null) { Hashtable tagInfo = CacheLoaderUtil.GetTagInfo(item.Value, item.Tags); if (tagInfo != null) { hashtable.Add("tag-info", tagInfo); } } if (item.NamedTags != null) { try { Hashtable hashtable3 = CacheLoaderUtil.GetNamedTagsInfo(item.Value, item.NamedTags, typeInfoMap); if (hashtable3 != null) { hashtable.Add("named-tag-info", hashtable3); } } catch (Exception exception) { throw new OperationFailedException("Error occurred while synchronization with data source; " + exception.Message); } } if (!item.Value.GetType().IsSerializable&& !_type.IsAssignableFrom(item.Value.GetType())) { throw new OperationFailedException("Read through provider returned an object that is not serializable."); } serializableObject = SerializationUtil.SafeSerialize(serializableObject, _context.SerializationContext, ref flag); if (_context.CompressionEnabled) { item.Value = CompressionUtil.Compress(item.Value as byte[], ref flag, _context.CompressionThreshold); } val = UserBinaryObject.CreateUserBinaryObject(serializableObject as byte[]); EvictionHint evictionHint = new PriorityEvictionHint(item.ItemPriority); ExpirationHint expiryHint = DependencyHelper.GetExpirationHint(item.Dependency, item.AbsoluteExpiration, item.SlidingExpiration); if (expiryHint != null) { expiryHint.CacheKey = key; if (item.ResyncItemOnExpiration) { expiryHint.SetBit(2); } } cacheEntry = new CacheEntry(val, expiryHint, evictionHint); cacheEntry.Flag = flag; cacheEntry.GroupInfo = new GroupInfo(item.Group, item.SubGroup); cacheEntry.QueryInfo = hashtable; cacheEntry.ResyncProviderName = (item.ResyncProviderName == null) ? null : item.ResyncProviderName.ToLower(); } return(val); }