コード例 #1
0
        private static int InvalidatePageCacheAll()
        {
            var count = CachePages.CountTable(0);

            CachePages.TruncateTable();
            return(count);
        }
コード例 #2
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            // Make sure this reflects changes
            InvalidatePageCache();
            var heading = PageCache.Politicians.GetPoliticianName(PoliticianKey);

            if (heading != H1.InnerHtml)
            {
                H1.InnerHtml = heading;
                UpdatePanelHeading.Update();
            }
            // This isn't available at Page_Load time
            if (PageCachingSubHeadingWithHelp.FindTemplateControl("ViewIntroLink") is HtmlAnchor
                viewIntroLink)
            {
                viewIntroLink.HRef = IntroPageUrl;
            }

            if (PageCachingSubHeadingWithHelp.FindTemplateControl("CacheExpirationMsg") is
                HtmlGenericControl cacheExpirationMsg)
            {
                cacheExpirationMsg.InnerText =
                    CachePages.DisplayExpiration(MemCache.CacheExpiration);
            }

            // We handle post-update processing here so we only have to do it once per postback,
            // not on each field.
            if (_UpdateCount <= 0)
            {
                return;
            }
            Politicians.IncrementDataUpdatedCount(PoliticianKey);
        }
コード例 #3
0
        private static void InvalidatePageCacheAll()
        {
            var count = CachePages.CountTable(0);

            VotePage.LogInfo("LocalCacheInvalidation", "Begin InvalidatePageCacheAll:" +
                             count);
            CachePages.TruncateTable();
            VotePage.LogInfo("LocalCacheInvalidation", "End InvalidatePageCacheAll:" +
                             count);
        }
コード例 #4
0
        private void SetAllCacheLabels()
        {
            var cacheRemovedAll = CacheControl.GetWhenCleared();

            if (cacheRemovedAll != null)
            {
                LabelAllPagesLastRemoved.Text = cacheRemovedAll.Value.DbDateToShortDateTime(true);
            }
            LabelAllPagesCurrent.Text = CachePages.CountTable()
                                        .ToString(CultureInfo.InvariantCulture);
        }
コード例 #5
0
 private static void SaveLocalCacheBlob(string cacheType, string cacheKey,
                                        DateTime dateStamp, byte[] cacheBlob)
 {
     // Save the rendered page in the local cache store.
     // We ignore errors because parallel threads may try to create an
     // identical cache entry
     try
     {
         CachePages.Upsert(cacheType, cacheKey, dateStamp, cacheBlob);
     }
     catch
     {
         // ignored
     }
 }
コード例 #6
0
        private string GetCacheImage()
        {
            var cacheType  = GetCacheType();
            var cacheKey   = GetCacheKey();
            var expiration = MemCache.CacheExpiration;
            var fuzzFactor = MemCache.CacheFuzzFactor;

            // apply fuzz factor
            var fuzz = Convert.ToInt32(Math.Round(expiration * (fuzzFactor / 100.0)));

            if (fuzz != 0)
            {
                lock (Random)
                    expiration += Random.Next(-fuzz, fuzz);
            }
            var minDateStamp = DateTime.UtcNow - new TimeSpan(0, expiration, 0);

            byte[] cacheBlob      = null;
            var    localBlobTable = CachePages.GetUnexpiredPageImage(cacheType, cacheKey,
                                                                     minDateStamp);

            if (localBlobTable.Count == 1)
            {
                cacheBlob = localBlobTable[0].PageImage;
                Interlocked.Increment(ref CurrentStatistics.PagesServedFromLocalCache);
            }
            else
            {
                var commonBlobTable =
                    DB.VoteCache.CachePages.GetUnexpiredPageImage(cacheType, cacheKey,
                                                                  minDateStamp);
                if (commonBlobTable.Count == 1)
                {
                    cacheBlob = commonBlobTable[0].PageImage;
                    SaveLocalCacheBlob(cacheType, cacheKey, commonBlobTable[0].DateStamp,
                                       cacheBlob);
                    Interlocked.Increment(ref CurrentStatistics.PagesServedFromCommonCache);
                }
                else
                {
                    Interlocked.Increment(ref CurrentStatistics.PagesCreated);
                }
            }

            if (_LastStatisticsSnapshot.SnapshotTime + StatisticsSnapshotInterval <
                DateTime.UtcNow)
            {
                // May need to snapshot statistics, but make sure only one thread does it
                if (Interlocked.Exchange(ref _SnapshottingStatistics, 1) == 0)
                // it's our job
                {
                    var previousSnapshot = _LastStatisticsSnapshot;
                    _LastStatisticsSnapshot = CurrentStatistics.Clone();
                    _LastStatisticsSnapshot.SnapshotTime = DateTime.UtcNow;
                    LogInfo("PageCaching",
                            $"Page caching from {previousSnapshot.SnapshotTime} to {_LastStatisticsSnapshot.SnapshotTime}:" +
                            $" {_LastStatisticsSnapshot.PagesServedFromMemoryCache - previousSnapshot.PagesServedFromMemoryCache} from memory cache," +
                            $" {_LastStatisticsSnapshot.PagesServedFromLocalCache - previousSnapshot.PagesServedFromLocalCache} from local cache," +
                            $" {_LastStatisticsSnapshot.PagesServedFromCommonCache - previousSnapshot.PagesServedFromCommonCache} from common cache," +
                            $" {_LastStatisticsSnapshot.PagesCreated - previousSnapshot.PagesCreated} created");
                    Interlocked.Exchange(ref _SnapshottingStatistics, 0);
                }
            }

            return(cacheBlob == null ? null : Encoding.UTF8.GetString(cacheBlob));
        }