public static void RefreshContentTypes(AppCaches appCaches)
    {
        // we could try to have a mechanism to notify the PublishedCachesService
        // and figure out whether published items were modified or not... keep it
        // simple for now, just clear the whole thing
        appCaches.ClearPartialViewCache();

        appCaches.IsolatedCaches.ClearCache <PublicAccessEntry>();
        appCaches.IsolatedCaches.ClearCache <IContent>();
    }
    /// <summary>
    ///     Refreshes the publish snapshot service and if there are published changes ensures that partial view caches are
    ///     refreshed too
    /// </summary>
    /// <param name="service"></param>
    /// <param name="appCaches"></param>
    /// <param name="payloads"></param>
    internal static void NotifyPublishedSnapshotService(IPublishedSnapshotService service, AppCaches appCaches, JsonPayload[] payloads)
    {
        service.Notify(payloads, out _, out var publishedChanged);

        if (payloads.Any(x => x.ChangeTypes.HasType(TreeChangeTypes.RefreshAll)) || publishedChanged)
        {
            // when a public version changes
            appCaches.ClearPartialViewCache();
        }
    }
        private void ClearCache(int id)
        {
            _idkMap.ClearCache(id);
            AppCaches.ClearPartialViewCache();

            var memberCache = AppCaches.IsolatedCaches.Get <IMember>();

            if (memberCache)
            {
                memberCache.Result.Clear(RepositoryCacheKeys.GetKey <IMember>(id));
            }
        }
示例#4
0
        private void ClearCache(params JsonPayload[] payloads)
        {
            AppCaches.ClearPartialViewCache();
            var memberCache = AppCaches.IsolatedCaches.Get <IMember>();

            foreach (var p in payloads)
            {
                _idkMap.ClearCache(p.Id);
                if (memberCache)
                {
                    memberCache.Result.Clear(RepositoryCacheKeys.GetKey <IMember, int>(p.Id));
                    memberCache.Result.Clear(RepositoryCacheKeys.GetKey <IMember, string>(p.Username));
                }
            }
        }
示例#5
0
    public override void Refresh(JsonPayload[]?payloads)
    {
        if (payloads == null)
        {
            return;
        }

        _publishedSnapshotService.Notify(payloads, out var anythingChanged);

        if (anythingChanged)
        {
            AppCaches.ClearPartialViewCache();
            AppCaches.RuntimeCache.ClearByKey(CacheKeys.MediaRecycleBinCacheKey);

            Attempt <IAppPolicyCache?> mediaCache = AppCaches.IsolatedCaches.Get <IMedia>();

            foreach (JsonPayload payload in payloads)
            {
                if (payload.ChangeTypes == TreeChangeTypes.Remove)
                {
                    _idKeyMap.ClearCache(payload.Id);
                }

                if (!mediaCache.Success)
                {
                    continue;
                }

                // repository cache
                // it *was* done for each pathId but really that does not make sense
                // only need to do it for the current media
                mediaCache.Result?.Clear(RepositoryCacheKeys.GetKey <IMedia, int>(payload.Id));
                mediaCache.Result?.Clear(RepositoryCacheKeys.GetKey <IMedia, Guid?>(payload.Key));

                // remove those that are in the branch
                if (payload.ChangeTypes.HasTypesAny(TreeChangeTypes.RefreshBranch | TreeChangeTypes.Remove))
                {
                    var pathid = "," + payload.Id + ",";
                    mediaCache.Result?.ClearOfType <IMedia>((_, v) => v.Path?.Contains(pathid) ?? false);
                }
            }
        }

        base.Refresh(payloads);
    }
        private ServerResponse ClearCacheFor(string cache)
        {
            try
            {
                if (cache == "Request" || cache == "all")
                {
                    caches.RequestCache.Clear();
                }
                else if (cache == "Runtime" || cache == "all")
                {
                    caches.RuntimeCache.Clear();
                }
                else if (cache == "Isolated" || cache == "all")
                {
                    caches.IsolatedCaches.ClearAllCaches();
                }
                else if (cache == "Partial" || cache == "all")
                {
                    caches.ClearPartialViewCache();
                }
                else
                {
                    return(new ServerResponse(cache + " Is not a valid cache type", ServerResponseType.Warning));
                }

                if (cache == "all")
                {
                    return(new ServerResponse("All Caches were successfully cleared", ServerResponseType.Success));
                }
                else
                {
                    return(new ServerResponse("The " + cache + " Cache was successfully cleared", ServerResponseType.Success));
                }
            }
            catch (Exception ex)
            {
                return(new ServerResponse("Error clearing cache: " + ex.Message, ServerResponseType.Error));
            }
        }
        public override void Refresh(JsonPayload[] payloads)
        {
            AppCaches.RuntimeCache.ClearOfType <PublicAccessEntry>();

            var idsRemoved    = new HashSet <int>();
            var isolatedCache = AppCaches.IsolatedCaches.GetOrCreate <IContent>();

            foreach (var payload in payloads)
            {
                isolatedCache.Clear(RepositoryCacheKeys.GetKey <IContent>(payload.Id));

                _idkMap.ClearCache(payload.Id);

                // remove those that are in the branch
                if (payload.ChangeTypes.HasTypesAny(TreeChangeTypes.RefreshBranch | TreeChangeTypes.Remove))
                {
                    var pathid = "," + payload.Id + ",";
                    isolatedCache.ClearOfType <IContent>((k, v) => v.Path.Contains(pathid));
                }

                //if the item is being completely removed, we need to refresh the domains cache if any domain was assigned to the content
                if (payload.ChangeTypes.HasTypesAny(TreeChangeTypes.Remove))
                {
                    idsRemoved.Add(payload.Id);
                }
            }

            if (idsRemoved.Count > 0)
            {
                var assignedDomains = _domainService.GetAll(true).Where(x => x.RootContentId.HasValue && idsRemoved.Contains(x.RootContentId.Value)).ToList();

                if (assignedDomains.Count > 0)
                {
                    // TODO: this is duplicating the logic in DomainCacheRefresher BUT we cannot inject that into this because it it not registered explicitly in the container,
                    // and we cannot inject the CacheRefresherCollection since that would be a circular reference, so what is the best way to call directly in to the
                    // DomainCacheRefresher?

                    ClearAllIsolatedCacheByEntityType <IDomain>();
                    // note: must do what's above FIRST else the repositories still have the old cached
                    // content and when the PublishedCachesService is notified of changes it does not see
                    // the new content...
                    // notify
                    _publishedSnapshotService.Notify(assignedDomains.Select(x => new DomainCacheRefresher.JsonPayload(x.Id, DomainChangeTypes.Remove)).ToArray());
                }
            }

            // note: must do what's above FIRST else the repositories still have the old cached
            // content and when the PublishedCachesService is notified of changes it does not see
            // the new content...

            // TODO: what about this?
            // should rename it, and then, this is only for Deploy, and then, ???
            //if (Suspendable.PageCacheRefresher.CanUpdateDocumentCache)
            //  ...

            _publishedSnapshotService.Notify(payloads, out _, out var publishedChanged);

            if (payloads.Any(x => x.ChangeTypes.HasType(TreeChangeTypes.RefreshAll)) || publishedChanged)
            {
                // when a public version changes
                AppCaches.ClearPartialViewCache();
            }

            base.Refresh(payloads);
        }