public ScratchBufferFile(AbstractPager scratchPager, int scratchNumber)
        {
            _scratchPager        = scratchPager;
            _scratchNumber       = scratchNumber;
            _allocatedPagesCount = 0;

            scratchPager.AllocatedInBytesFunc = () => AllocatedPagesCount * Constants.Storage.PageSize;
            _strongRefToAllocateInBytesFunc   = new StrongReference <Func <long> > {
                Value = scratchPager.AllocatedInBytesFunc
            };
            MemoryInformation.DirtyMemoryObjects.TryAdd(_strongRefToAllocateInBytesFunc);

            DebugInfo = new ScratchFileDebugInfo(this);

            _disposeOnceRunner = new DisposeOnce <SingleAttempt>(() =>
            {
                _strongRefToAllocateInBytesFunc.Value = null; // remove ref (so if there's a left over refs in DirtyMemoryObjects but also function as _disposed = true for racy func invoke)
                MemoryInformation.DirtyMemoryObjects.TryRemove(_strongRefToAllocateInBytesFunc);
                _strongRefToAllocateInBytesFunc = null;

                _scratchPager.PagerState.DiscardOnTxCopy = true;
                _scratchPager.Dispose();
                ClearDictionaries();
            });
        }
 /// <summary>
 /// Adds an item with the specified key and value into cached data.
 /// Gets a cached object with the specified key.
 /// </summary>
 /// <value>The cached object or <c>null</c></value>
 public object this[object key]
 {
     get
     {
         object value     = null;
         object reference = _cache[key];
         if (reference != null)
         {
             if (reference is StrongReference)
             {
                 value = ((StrongReference)reference).Target;
             }
             else if (reference is WeakReference)
             {
                 value = ((WeakReference)reference).Target;
             }
         }
         return(value);
     }
     set
     {
         object reference = null;
         if (_cacheLevel.Equals(MemoryCacheLevel.Weak))
         {
             reference = new WeakReference(value);
         }
         else if (_cacheLevel.Equals(MemoryCacheLevel.Strong))
         {
             reference = new StrongReference(value);
         }
         _cache[key] = reference;
     }
 }
 public object this[object key]
 {
     get
     {
         object target = null;
         object obj3   = this._cache[key];
         if (obj3 != null)
         {
             if (obj3 is StrongReference)
             {
                 return(((StrongReference)obj3).Target);
             }
             if (obj3 is WeakReference)
             {
                 target = ((WeakReference)obj3).Target;
             }
         }
         return(target);
     }
     set
     {
         object obj2 = null;
         if (this._cacheLevel.Equals(MemoryCacheLevel.Weak))
         {
             obj2 = new WeakReference(value);
         }
         else if (this._cacheLevel.Equals(MemoryCacheLevel.Strong))
         {
             obj2 = new StrongReference(value);
         }
         this._cache[key] = obj2;
     }
 }
示例#4
0
            public ContainerSubscription(BaseContainer container, StrongReference <IAsyncCompletable> wr)
            {
                _container = container;
                Wr         = wr;
                if (wr.TryGetTarget(out var target))
                {
#pragma warning disable 618
                    _sr = target;
#pragma warning restore 618
                }
            }
		/// <summary>
		/// Adds an item with the specified key and value into cached data.
		/// Gets a cached object with the specified key.
		/// </summary>
		/// <value>The cached object or <c>null</c></value>
		public object this[object key]
		{
			get
			{
				object value = null;
				object reference = _cache[key];
				if (reference != null) 
				{
					if (reference is StrongReference) 
					{
						value = ((StrongReference) reference).Target;
					} 
					else if (reference is WeakReference) 
					{
						value = ((WeakReference) reference).Target;
					}
				}				
				return value;
			}
			set
			{
				object reference = null;
				if (_cacheLevel.Equals(MemoryCacheLevel.Weak)) 
				{
					reference = new WeakReference(value);
				} 
				else if (_cacheLevel.Equals(MemoryCacheLevel.Strong)) 
				{
					reference = new StrongReference(value);
				}
				_cache[key] = reference;	
			
			}
		}