示例#1
0
        public async Task Reload(string accessKey)
        {
            _accessKeyValidator.Validate(accessKey);

            _logger.LogTrace("Reloading all blog posts...");

            var   cacheTask = CacheTask;
            Cache?cache     = null;

            if (cacheTask != null)
            {
                try
                {
                    cache = await cacheTask;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error while retrieving current cache to clear.");
                }
            }

            var postCachesToDispose = cache?.PostsBySlug.Values.ToArray() ?? new PostCache[0];

            cacheTask = InitializeCache();
            HttpCache.Clear();
            CacheTask = cacheTask;
            try
            {
                await cacheTask;
            }
            catch (Exception ex)
            {
                CacheTask = null;
                _logger.LogError(ex, "Error while reloading all blog posts");
                throw;
            }
            finally
            {
                foreach (var postCache in postCachesToDispose)
                {
                    postCache.Dispose();
                }
            }
        }
示例#2
0
        public async Task Reload(string accessKey, string slug)
        {
            _accessKeyValidator.Validate(accessKey);

            _logger.LogTrace("Reloading blog post with slug {slug}...", slug);

            var cache = await InitializeCacheIfNeeded();

            var postCache = cache == null ? null : (cache.PostsBySlug.TryGetValue(slug, out var p) ? p : null);

            if (postCache == null)
            {
                _logger.LogWarning("Could not find post with slug {slug} to reload.", slug);
                return;
            }
            HttpCache.Clear(x =>
                            x == "/" || x == "/sitemap" || x.StartsWith("/rss") ||
                            (x.StartsWith("/blog") && !x.EndsWith(".png")) ||
                            (x.StartsWith("/blog/") && x.Contains($"{slug}")));
            postCache.Reset();
        }