Ejemplo n.º 1
0
        internal CacheExpires(CacheInternal cacheInternal)
        {
            _cacheInternal = cacheInternal;
            _buckets       = new ExpiresBucket[NUMBUCKETS];
            for (byte b = 0; b < _buckets.Length; b++)
            {
                _buckets[b] = new ExpiresBucket(this, b);
            }

            DateTime utcNow  = DateTime.UtcNow;
            TimeSpan due     = _tsPerBucket - (new TimeSpan(utcNow.Ticks % _tsPerBucket.Ticks));
            DateTime utcFire = utcNow + due;

            _iFlush = (int)(((utcFire.Ticks % _tsPerCycle.Ticks) / _tsPerBucket.Ticks) % NUMBUCKETS);
#if DBG
            if (!Debug.IsTagPresent("Timer") || Debug.IsTagEnabled("Timer"))
#endif
            {
                _timer = new Timer(new TimerCallback(this.TimerCallback), null, due.Ticks / TimeSpan.TicksPerMillisecond, Msec.ONE_MINUTE);
            }
        }
Ejemplo n.º 2
0
 internal void SetCacheInternal(CacheInternal cacheInternal) {
     _cacheInternal = cacheInternal;
 }
 private void Init(bool isPublic, string[] filenamesArg, string[] cachekeysArg, CacheDependency dependency, DateTime utcStart)
 {
     string[]      strArray;
     string[]      strArray2;
     DepFileInfo[] infoArray  = s_depFileInfosEmpty;
     CacheEntry[]  entryArray = s_entriesEmpty;
     this._bits = new SafeBitVector32(0);
     if (filenamesArg != null)
     {
         strArray = (string[])filenamesArg.Clone();
     }
     else
     {
         strArray = null;
     }
     if (cachekeysArg != null)
     {
         strArray2 = (string[])cachekeysArg.Clone();
     }
     else
     {
         strArray2 = null;
     }
     this._utcLastModified = DateTime.MinValue;
     try
     {
         if (strArray == null)
         {
             strArray = s_stringsEmpty;
         }
         else
         {
             foreach (string str in strArray)
             {
                 if (str == null)
                 {
                     throw new ArgumentNullException("filenamesArg");
                 }
                 if (isPublic)
                 {
                     InternalSecurityPermissions.PathDiscovery(str).Demand();
                 }
             }
         }
         if (strArray2 == null)
         {
             strArray2 = s_stringsEmpty;
         }
         else
         {
             string[] strArray4 = strArray2;
             for (int i = 0; i < strArray4.Length; i++)
             {
                 if (strArray4[i] == null)
                 {
                     throw new ArgumentNullException("cachekeysArg");
                 }
             }
         }
         if (dependency == null)
         {
             dependency = s_dependencyEmpty;
         }
         else
         {
             if (dependency.GetType() != s_dependencyEmpty.GetType())
             {
                 throw new ArgumentException(System.Web.SR.GetString("Invalid_Dependency_Type"));
             }
             object   obj2 = dependency._depFileInfos;
             object   obj3 = dependency._entries;
             DateTime time = dependency._utcLastModified;
             if (dependency._bits[4])
             {
                 this._bits[4] = true;
                 this.DisposeInternal();
                 return;
             }
             if (obj2 != null)
             {
                 if (obj2 is DepFileInfo)
                 {
                     infoArray = new DepFileInfo[] { (DepFileInfo)obj2 };
                 }
                 else
                 {
                     infoArray = (DepFileInfo[])obj2;
                 }
                 foreach (DepFileInfo info in infoArray)
                 {
                     string path = info._filename;
                     if (path == null)
                     {
                         this._bits[4] = true;
                         this.DisposeInternal();
                         return;
                     }
                     if (isPublic)
                     {
                         InternalSecurityPermissions.PathDiscovery(path).Demand();
                     }
                 }
             }
             if (obj3 != null)
             {
                 if (obj3 is CacheEntry)
                 {
                     entryArray = new CacheEntry[] { (CacheEntry)obj3 };
                 }
                 else
                 {
                     entryArray = (CacheEntry[])obj3;
                     CacheEntry[] entryArray4 = entryArray;
                     for (int j = 0; j < entryArray4.Length; j++)
                     {
                         if (entryArray4[j] == null)
                         {
                             this._bits[4] = true;
                             this.DisposeInternal();
                             return;
                         }
                     }
                 }
             }
             this._utcLastModified = time;
         }
         int num = infoArray.Length + strArray.Length;
         if (num > 0)
         {
             int                    num2;
             DepFileInfo[]          infoArray2         = new DepFileInfo[num];
             FileChangeEventHandler callback           = new FileChangeEventHandler(this.FileChange);
             FileChangesMonitor     fileChangesMonitor = HttpRuntime.FileChangesMonitor;
             for (num2 = 0; num2 < num; num2++)
             {
                 infoArray2[num2] = new DepFileInfo();
             }
             num2 = 0;
             foreach (DepFileInfo info2 in infoArray)
             {
                 string alias = info2._filename;
                 fileChangesMonitor.StartMonitoringPath(alias, callback, out infoArray2[num2]._fad);
                 infoArray2[num2]._filename = alias;
                 num2++;
             }
             DateTime minValue = DateTime.MinValue;
             foreach (string str5 in strArray)
             {
                 DateTime time3 = fileChangesMonitor.StartMonitoringPath(str5, callback, out infoArray2[num2]._fad);
                 infoArray2[num2]._filename = str5;
                 num2++;
                 if (time3 > this._utcLastModified)
                 {
                     this._utcLastModified = time3;
                 }
                 if (utcStart < DateTime.MaxValue)
                 {
                     if (minValue == DateTime.MinValue)
                     {
                         minValue = DateTime.UtcNow;
                     }
                     if ((time3 >= utcStart) && ((time3 - minValue) <= FUTURE_FILETIME_BUFFER))
                     {
                         this._bits[4] = true;
                         break;
                     }
                 }
             }
             if (infoArray2.Length == 1)
             {
                 this._depFileInfos = infoArray2[0];
             }
             else
             {
                 this._depFileInfos = infoArray2;
             }
         }
         int num3 = entryArray.Length + strArray2.Length;
         if ((num3 > 0) && !this._bits[4])
         {
             CacheEntry[] entryArray2 = new CacheEntry[num3];
             int          num4        = 0;
             foreach (CacheEntry entry2 in entryArray)
             {
                 entry2.AddCacheDependencyNotify(this);
                 entryArray2[num4++] = entry2;
             }
             CacheInternal cacheInternal = HttpRuntime.CacheInternal;
             foreach (string str6 in strArray2)
             {
                 CacheEntry entry3 = (CacheEntry)cacheInternal.DoGet(isPublic, str6, CacheGetOptions.ReturnCacheEntry);
                 if (entry3 != null)
                 {
                     entry3.AddCacheDependencyNotify(this);
                     entryArray2[num4++] = entry3;
                     if (entry3.UtcCreated > this._utcLastModified)
                     {
                         this._utcLastModified = entry3.UtcCreated;
                     }
                     if ((entry3.State == CacheEntry.EntryState.AddedToCache) && (entry3.UtcCreated <= utcStart))
                     {
                         continue;
                     }
                     this._bits[4] = true;
                 }
                 else
                 {
                     this._bits[4] = true;
                 }
                 break;
             }
             if (entryArray2.Length == 1)
             {
                 this._entries = entryArray2[0];
             }
             else
             {
                 this._entries = entryArray2;
             }
         }
         this._bits[1] = true;
         if (dependency._bits[4])
         {
             this._bits[4] = true;
         }
         if (this._bits[0x10] || this._bits[4])
         {
             this.DisposeInternal();
         }
     }
     catch
     {
         this._bits[1] = true;
         this.DisposeInternal();
         throw;
     }
     finally
     {
         this.InitUniqueID();
     }
 }
 internal void SetCacheInternal(CacheInternal cacheInternal)
 {
     this._cacheInternal = cacheInternal;
     this._cachePublic.SetCacheInternal(cacheInternal);
 }
 internal void SetCacheInternal(CacheInternal cacheInternal)
 {
     this._cacheInternal = cacheInternal;
     this._cachePublic.SetCacheInternal(cacheInternal);
 }
    internal MemoryBuildResultCache(CacheInternal cache) {
        _cache = cache;

        // Register an AssemblyLoad event
        AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(OnAssemblyLoad);
    }
Ejemplo n.º 7
0
 internal AspNetCache(AspNetCache cache, bool isPublic)
 {
     _isPublic      = isPublic;
     _cacheInternal = cache._cacheInternal;
     Interlocked.Increment(ref _cacheInternal._refCount);
 }
        internal static void PollDatabaseForChanges(DatabaseNotifState dbState, bool fromTimer)
        {
            SqlDataReader reader        = null;
            SqlConnection sqlConn       = null;
            SqlCommand    sqlCmd        = null;
            CacheInternal cacheInternal = HttpRuntime.CacheInternal;
            bool          flag          = false;
            Exception     exception     = null;
            SqlException  exception2    = null;

            if (s_shutdown)
            {
                return;
            }
            if (((dbState._refCount == 0) && fromTimer) && dbState._init)
            {
                return;
            }
            if (Interlocked.CompareExchange(ref dbState._rqInCallback, 1, 0) != 0)
            {
                int num2;
                if (fromTimer)
                {
                    return;
                }
                HttpContext current = HttpContext.Current;
                if (current == null)
                {
                    num2 = 30;
                }
                else
                {
                    num2 = Math.Max(current.Timeout.Seconds / 3, 30);
                }
                DateTime time = DateTime.UtcNow.Add(new TimeSpan(0, 0, num2));
                do
                {
                    if (Interlocked.CompareExchange(ref dbState._rqInCallback, 1, 0) == 0)
                    {
                        goto Label_00EA;
                    }
                    Thread.Sleep(250);
                    if (s_shutdown)
                    {
                        return;
                    }
                }while (Debugger.IsAttached || (DateTime.UtcNow <= time));
                throw new HttpException(System.Web.SR.GetString("Cant_connect_sql_cache_dep_database_polling", new object[] { dbState._database }));
            }
Label_00EA:
            try
            {
                try
                {
                    Interlocked.Increment(ref s_activePolling);
                    dbState.GetConnection(out sqlConn, out sqlCmd);
                    reader = sqlCmd.ExecuteReader();
                    if (!s_shutdown)
                    {
                        flag = true;
                        Hashtable hashtable = (Hashtable)dbState._tables.Clone();
                        while (reader.Read())
                        {
                            string table      = reader.GetString(0);
                            int    num        = reader.GetInt32(1);
                            string moniterKey = GetMoniterKey(dbState._database, table);
                            object obj2       = cacheInternal[moniterKey];
                            if (obj2 == null)
                            {
                                cacheInternal.UtcAdd(moniterKey, num, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                                dbState._tables.Add(table, null);
                            }
                            else if (num != ((int)obj2))
                            {
                                cacheInternal.UtcInsert(moniterKey, num, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                            }
                            hashtable.Remove(table);
                        }
                        foreach (object obj3 in hashtable.Keys)
                        {
                            dbState._tables.Remove((string)obj3);
                            cacheInternal.Remove(GetMoniterKey(dbState._database, (string)obj3));
                        }
                        if (dbState._pollSqlError != 0)
                        {
                            dbState._pollSqlError = 0;
                        }
                    }
                }
                catch (Exception exception3)
                {
                    exception  = exception3;
                    exception2 = exception3 as SqlException;
                    if (exception2 != null)
                    {
                        dbState._pollSqlError = exception2.Number;
                    }
                    else
                    {
                        dbState._pollSqlError = 0;
                    }
                }
                finally
                {
                    try
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                        dbState.ReleaseConnection(ref sqlConn, ref sqlCmd, exception != null);
                    }
                    catch
                    {
                    }
                    lock (dbState)
                    {
                        dbState._pollExpt = exception;
                        if ((dbState._notifEnabled && !flag) && ((exception != null) && (dbState._pollSqlError == 0xafc)))
                        {
                            foreach (object obj4 in dbState._tables.Keys)
                            {
                                try
                                {
                                    cacheInternal.Remove(GetMoniterKey(dbState._database, (string)obj4));
                                }
                                catch
                                {
                                }
                            }
                            dbState._tables.Clear();
                        }
                        dbState._notifEnabled     = flag;
                        dbState._utcTablesUpdated = DateTime.UtcNow;
                    }
                    if (!dbState._init)
                    {
                        dbState._init = true;
                    }
                    Interlocked.Decrement(ref s_activePolling);
                    Interlocked.Exchange(ref dbState._rqInCallback, 0);
                }
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 9
0
 public AspNetCache()
 {
     _cacheInternal = CacheInternal.Create();
     Interlocked.Exchange(ref _cacheInternal._refCount, 1);
 }
Ejemplo n.º 10
0
 private void CreateCache()
 {
   lock (this)
   {
     if (this._cacheInternal != null)
       return;
     this._cacheInternal = CacheInternal.Create();
   }
 }
 internal void SetCacheInternal(CacheInternal cacheInternal)
 {
     this._cacheInternal = cacheInternal;
 }
Ejemplo n.º 12
0
        internal int FlushUnderUsedItems(int maxFlush)
        {
            if (_cInUse == 0)
            {
                return(0);
            }

            Debug.Assert(maxFlush > 0, "maxFlush is not greater than 0, instead is " + maxFlush);

            int       flushed = 0;
            ArrayList entriesToRemove = new ArrayList();
            DateTime  utcNow = DateTime.UtcNow;
            int       prev, prevNext;
            DateTime  utcDate;
            int       index;

            lock (this) {
                // walk the list backwards, removing items
                for (prev = _entries[0].ref1.prev;
                     prev != 0 && flushed < maxFlush && _cInUse > 0;
                     prev = prevNext)
                {
                    // set prevNext before possibly freeing an item
                    prevNext = _entries[-prev].ref2.prev;
                    while (prevNext > 0)
                    {
                        Debug.Assert(prevNext != 0, "prevNext != 0");
                        prevNext = _entries[prevNext].ref1.prev;
                    }

                    // look only at ref2 items
                    Debug.Assert(prev < 0, "prev < 0");
                    index   = -prev;
                    utcDate = _entries[index].utcDate;
                    Debug.Assert(utcDate != DateTime.MinValue, "utcDate != DateTime.MinValue");

                    if (utcNow - utcDate > CacheUsage.NEWADD_INTERVAL)
                    {
                        CacheEntry cacheEntry = _entries[index].cacheEntry;
                        Debug.Trace("CacheUsageFlushUnderUsedItem", "Flushing underused items, item=" + cacheEntry.Key + ", bucket=" + _bucket);

                        entriesToRemove.Add(cacheEntry);
                        flushed++;
                    }

                    Debug.Assert(-_entries.Length < prevNext && prevNext < _entries.Length, "-_entries.Length < prevNext && prevNext < _entries.Length");
                }

                Debug.Validate("CacheValidateUsage", this);
                Debug.Dump("CacheUsageFlush", this);
            }

            CacheInternal cacheInternal = _cacheUsage.CacheInternal;

            foreach (CacheEntry cacheEntry in entriesToRemove)
            {
                cacheInternal.Remove(cacheEntry, CacheItemRemovedReason.Underused);
            }

            Debug.Trace("CacheUsageFlushUnderUsedTotal", "Removed " + entriesToRemove.Count +
                        " underused items; Time=" + DateTime.UtcNow.ToLocalTime());

            return(flushed);
        }
Ejemplo n.º 13
0
        object _onRemovedTargets;                           /* targets of OnRemove notification */

        /*
         * ctor.
         */

        internal CacheEntry(
            String key,
            Object value,
            CacheDependency dependency,
            CacheItemRemovedCallback onRemovedHandler,
            DateTime utcAbsoluteExpiration,
            TimeSpan slidingExpiration,
            CacheItemPriority priority,
            bool isPublic,
            CacheInternal cache) :

            base(key, isPublic)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (slidingExpiration < TimeSpan.Zero || OneYear < slidingExpiration)
            {
                throw new ArgumentOutOfRangeException("slidingExpiration");
            }

            if (utcAbsoluteExpiration != Cache.NoAbsoluteExpiration && slidingExpiration != Cache.NoSlidingExpiration)
            {
                throw new ArgumentException(SR.GetString(SR.Invalid_expiration_combination));
            }

            if (priority < CacheItemPriorityMin || CacheItemPriorityMax < priority)
            {
                throw new ArgumentOutOfRangeException("priority");
            }

            _value            = value;
            _dependency       = dependency;
            _onRemovedTargets = onRemovedHandler;

            _utcCreated        = DateTime.UtcNow;
            _slidingExpiration = slidingExpiration;
            if (_slidingExpiration > TimeSpan.Zero)
            {
                _utcExpires = _utcCreated + _slidingExpiration;
            }
            else
            {
                _utcExpires = utcAbsoluteExpiration;
            }

            _expiresEntryRef = ExpiresEntryRef.INVALID;
            _expiresBucket   = 0xff;

            _usageEntryRef = UsageEntryRef.INVALID;
            if (priority == CacheItemPriority.NotRemovable)
            {
                _usageBucket = 0xff;
            }
            else
            {
                _usageBucket = (byte)(priority - 1);
            }

            _cache = cache;
        }
Ejemplo n.º 14
0
 internal void SetCacheInternal(CacheInternal cacheInternal)
 {
     this._cacheInternal = cacheInternal;
 }
Ejemplo n.º 15
0
 internal void AddSRefTarget(CacheInternal c) {
     _srefMultiple.AddSRefTarget(c);
 }
Ejemplo n.º 16
0
 internal AspNetCache(bool isPublic)
 {
     _isPublic      = isPublic;
     _cacheInternal = CacheInternal.Create();
     Interlocked.Exchange(ref _cacheInternal._refCount, 1);
 }
Ejemplo n.º 17
0
 internal void SetCacheInternal(CacheInternal cacheInternal) {
     _cacheInternal = cacheInternal;
     _cachePublic.SetCacheInternal(cacheInternal);
 }
 internal MemoryBuildResultCache(CacheInternal cache)
 {
     this._cache = cache;
     AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(this.OnAssemblyLoad);
 }