Ejemplo n.º 1
0
        // This method is only used by the CommonCacheCleanup which is run via the
        // Windows task scheduler
        public static void CleanUpCacheInvalidation()
        {
            string message;

            try
            {
                VotePage.LogInfo("CleanUpCacheInvalidation", "Started");

                // Get the number of days to retain, default to 7
                var daysString =
                    ConfigurationManager.AppSettings["VoteCommonCacheInvalidationRetentionDays"];
                if (!int.TryParse(daysString, out var days))
                {
                    days = 7;
                }

                // Convert to a past DateTime
                var expiration = DateTime.UtcNow - new TimeSpan(days, 0, 0, 0);

                // Do it
                var deleted = CacheInvalidation.DeleteExpiredTransactions(expiration);

                message =
                    $"{deleted} CacheInvalidation rows deleted";
            }
            catch (Exception ex)
            {
                VotePage.LogException("CleanUpCacheInvalidation", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }

            VotePage.LogInfo("CleanUpCacheInvalidation", message);
        }