Пример #1
0
        public static List <Role> FindRoles(this string systemID, string parentID, bool updateCache = true)
        {
            if (string.IsNullOrWhiteSpace(systemID))
            {
                return(new List <Role>());
            }
            var filter = RoleProcessor.GetRolesFilter(systemID, parentID);
            var sort   = Sorts <Role> .Ascending("Title");

            var roles = Role.Find(filter, sort, 0, 1, Extensions.GetCacheKey(filter, sort, 0, 1));

            roles.ForEach(role => role.Set(updateCache));
            return(roles);
        }
Пример #2
0
        public static async Task <List <Role> > FindRolesAsync(this string systemID, string parentID, CancellationToken cancellationToken = default, bool updateCache = true)
        {
            if (string.IsNullOrWhiteSpace(systemID))
            {
                return(new List <Role>());
            }
            var filter = RoleProcessor.GetRolesFilter(systemID, parentID);
            var sort   = Sorts <Role> .Ascending("Title");

            var roles = await Role.FindAsync(filter, sort, 0, 1, Extensions.GetCacheKey(filter, sort, 0, 1), cancellationToken).ConfigureAwait(false);

            await roles.ForEachAsync((role, token) => role.SetAsync(updateCache, token), cancellationToken).ConfigureAwait(false);

            return(roles);
        }
Пример #3
0
        internal static Task ClearRelatedCacheAsync(this Role role, string oldParentID, CancellationToken cancellationToken, string correlationID = null)
        {
            var sort = Sorts <Role> .Ascending("Title");

            var dataCacheKeys = Extensions.GetRelatedCacheKeys(RoleProcessor.GetRolesFilter(role.SystemID), sort);

            if (!string.IsNullOrWhiteSpace(role.ParentID) && role.ParentID.IsValidUUID())
            {
                dataCacheKeys = Extensions.GetRelatedCacheKeys(RoleProcessor.GetRolesFilter(role.SystemID, role.ParentID), sort).Concat(dataCacheKeys).ToList();
            }
            if (!string.IsNullOrWhiteSpace(oldParentID) && oldParentID.IsValidUUID())
            {
                dataCacheKeys = Extensions.GetRelatedCacheKeys(RoleProcessor.GetRolesFilter(role.SystemID, oldParentID), sort).Concat(dataCacheKeys).ToList();
            }
            dataCacheKeys = dataCacheKeys.Distinct(StringComparer.OrdinalIgnoreCase).ToList();
            if (Utility.WriteCacheLogs)
            {
                Utility.WriteLogAsync(correlationID, $"Clear related cache of role [{role.ID} => {role.Title}]\r\n{dataCacheKeys.Count} keys => {dataCacheKeys.Join(", ")}", ServiceBase.ServiceComponent.CancellationToken, "Caches").Run();
            }
            return(Utility.Cache.RemoveAsync(dataCacheKeys, cancellationToken));
        }