コード例 #1
0
        public QuotaServiceCache(IConfiguration Configuration, ICacheNotify <QuotaCacheItem> cacheNotify)
        {
            if (Configuration["core:enable-quota-cache"] == null)
            {
                QuotaCacheEnabled = true;
            }
            else
            {
                QuotaCacheEnabled = !bool.TryParse(Configuration["core:enable-quota-cache"], out var enabled) || enabled;
            }

            CacheNotify = cacheNotify;
            Cache       = AscCache.Memory;
            Interval    = new TrustInterval();

            cacheNotify.Subscribe((i) =>
            {
                if (i.Key == KEY_QUOTA_ROWS)
                {
                    Interval.Expire();
                }
                else if (i.Key == KEY_QUOTA)
                {
                    Cache.Remove(KEY_QUOTA);
                }
            }, CacheNotifyAction.Any);
        }
コード例 #2
0
        public CachedQuotaService(IQuotaService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            this.service    = service;
            cache           = AscCache.Memory;
            interval        = new TrustInterval();
            CacheExpiration = TimeSpan.FromMinutes(10);

            cacheNotify = AscCache.Notify;
            cacheNotify.Subscribe <QuotaCacheItem>((i, a) =>
            {
                if (i.Key == KEY_QUOTA_ROWS)
                {
                    interval.Expire();
                }
                else if (i.Key == KEY_QUOTA)
                {
                    cache.Remove(KEY_QUOTA);
                }
            });
        }
コード例 #3
0
 public CachedQuotaService(DbQuotaService service, QuotaServiceCache quotaServiceCache)
 {
     this.service      = service ?? throw new ArgumentNullException("service");
     QuotaServiceCache = quotaServiceCache;
     cache             = quotaServiceCache.Cache;
     interval          = new TrustInterval();
     CacheExpiration   = TimeSpan.FromMinutes(10);
     cacheNotify       = quotaServiceCache.CacheNotify;
 }
コード例 #4
0
        private void InvalidateCache(UserInfoCacheItem userInfo)
        {
            if (CoreBaseSettings.Personal && userInfo != null)
            {
                var key = GetUserCacheKeyForPersonal(userInfo.Tenant, userInfo.ID.FromByteString());
                Cache.Remove(key);
            }

            TrustInterval.Expire();
        }
コード例 #5
0
        public CachedQuotaService(IQuotaService service)
        {
            if (service == null) throw new ArgumentNullException("service");

            this.service = service;
            this.cache = new AspCache();
            this.interval = new TrustInterval();
            this.syncQuotaRows = 0;

            CacheExpiration = TimeSpan.FromMinutes(10);
        }
コード例 #6
0
        public CachedUserService(IUserService service)
        {
            if (service == null) throw new ArgumentNullException("service");

            this.service = service;
            cache = AscCache.Default;
            trustInterval = new TrustInterval();

            CacheExpiration = TimeSpan.FromMinutes(20);
            DbExpiration = TimeSpan.FromMinutes(1);
            PhotoExpiration = TimeSpan.FromMinutes(10);
        }
コード例 #7
0
        public CachedQuotaService(IQuotaService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            this.service       = service;
            this.cache         = new AspCache();
            this.interval      = new TrustInterval();
            this.syncQuotaRows = 0;

            CacheExpiration = TimeSpan.FromMinutes(10);
        }
コード例 #8
0
        public CachedTenantService(ITenantService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            this.service = service;
            cache        = new AspCache();
            interval     = new TrustInterval();

            CacheExpiration    = TimeSpan.FromHours(2);
            DbExpiration       = TimeSpan.FromSeconds(5);
            SettingsExpiration = TimeSpan.FromMinutes(10);
        }
コード例 #9
0
        public CachedUserService(IUserService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            this.service  = service;
            cache         = AscCache.Default;
            trustInterval = new TrustInterval();

            CacheExpiration = TimeSpan.FromMinutes(20);
            DbExpiration    = TimeSpan.FromMinutes(1);
            PhotoExpiration = TimeSpan.FromMinutes(10);
        }
コード例 #10
0
        public CachedUserService(
            DbUserService service,
            CoreBaseSettings coreBaseSettings,
            UserServiceCache userServiceCache
            )
        {
            this.service          = service ?? throw new ArgumentNullException("service");
            CoreBaseSettings      = coreBaseSettings;
            UserServiceCache      = userServiceCache;
            cache                 = userServiceCache.Cache;
            CacheUserInfoItem     = userServiceCache.CacheUserInfoItem;
            CacheUserPhotoItem    = userServiceCache.CacheUserPhotoItem;
            CacheGroupCacheItem   = userServiceCache.CacheGroupCacheItem;
            CacheUserGroupRefItem = userServiceCache.CacheUserGroupRefItem;
            trustInterval         = userServiceCache.TrustInterval;

            CacheExpiration = TimeSpan.FromMinutes(20);
            DbExpiration    = TimeSpan.FromMinutes(1);
            PhotoExpiration = TimeSpan.FromMinutes(10);
        }
コード例 #11
0
        public CachedUserService(IUserService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            this.service  = service;
            cache         = AscCache.Memory;
            trustInterval = new TrustInterval();

            CacheExpiration = TimeSpan.FromMinutes(20);
            DbExpiration    = TimeSpan.FromMinutes(1);
            PhotoExpiration = TimeSpan.FromMinutes(10);

            cacheNotify = AscCache.Notify;
            cacheNotify.Subscribe <UserInfo>((u, a) => InvalidateCache(u));
            cacheNotify.Subscribe <UserPhoto>((p, a) => cache.Remove(p.Key));
            cacheNotify.Subscribe <Group>((g, a) => InvalidateCache());
            cacheNotify.Subscribe <UserGroupRef>((r, a) => UpdateUserGroupRefCache(r, a == CacheNotifyAction.Remove));
        }
コード例 #12
0
        public UserServiceCache(
            CoreBaseSettings coreBaseSettings,
            ICacheNotify <UserInfoCacheItem> cacheUserInfoItem,
            ICacheNotify <UserPhotoCacheItem> cacheUserPhotoItem,
            ICacheNotify <GroupCacheItem> cacheGroupCacheItem,
            ICacheNotify <UserGroupRefCacheItem> cacheUserGroupRefItem)
        {
            TrustInterval         = new TrustInterval();
            Cache                 = AscCache.Memory;
            CoreBaseSettings      = coreBaseSettings;
            CacheUserInfoItem     = cacheUserInfoItem;
            CacheUserPhotoItem    = cacheUserPhotoItem;
            CacheGroupCacheItem   = cacheGroupCacheItem;
            CacheUserGroupRefItem = cacheUserGroupRefItem;

            cacheUserInfoItem.Subscribe((u) => InvalidateCache(u), CacheNotifyAction.Any);
            cacheUserPhotoItem.Subscribe((p) => Cache.Remove(p.Key), CacheNotifyAction.Remove);
            cacheGroupCacheItem.Subscribe((g) => InvalidateCache(), CacheNotifyAction.Any);

            cacheUserGroupRefItem.Subscribe((r) => UpdateUserGroupRefCache(r, true), CacheNotifyAction.Remove);
            cacheUserGroupRefItem.Subscribe((r) => UpdateUserGroupRefCache(r, false), CacheNotifyAction.InsertOrUpdate);
        }
コード例 #13
0
        public CachedUserService(IUserService service)
        {
            this.service  = service ?? throw new ArgumentNullException("service");
            cache         = AscCache.Memory;
            trustInterval = new TrustInterval();

            CacheExpiration = TimeSpan.FromMinutes(20);
            DbExpiration    = TimeSpan.FromMinutes(1);
            PhotoExpiration = TimeSpan.FromMinutes(10);

            cacheUserInfoItem     = new KafkaCache <UserInfoCacheItem>();
            cacheUserPhotoItem    = new KafkaCache <UserPhotoCacheItem>();
            cacheGroupCacheItem   = new KafkaCache <GroupCacheItem>();
            cacheUserGroupRefItem = new KafkaCache <UserGroupRefCacheItem>();

            cacheUserInfoItem.Subscribe((u) => InvalidateCache(u), CacheNotifyAction.Any);
            cacheUserPhotoItem.Subscribe((p) => cache.Remove(p.Key), CacheNotifyAction.Remove);
            cacheGroupCacheItem.Subscribe((g) => InvalidateCache(), CacheNotifyAction.Any);

            cacheUserGroupRefItem.Subscribe((r) => UpdateUserGroupRefCache(r, true), CacheNotifyAction.Remove);
            cacheUserGroupRefItem.Subscribe((r) => UpdateUserGroupRefCache(r, false), CacheNotifyAction.InsertOrUpdate);
        }
コード例 #14
0
        private void GetChangesFromDb()
        {
            if (Interlocked.CompareExchange(ref getchanges, 1, 0) == 0)
            {
                try
                {
                    if (trustInterval == null)
                    {
                        trustInterval = new TrustInterval();
                        trustInterval.Start(DbExpiration);
                    }
                    if (!trustInterval.Expired)
                    {
                        return;
                    }

                    var starttime = trustInterval.StartTime;
                    trustInterval.Start(DbExpiration);

                    //get and merge changes in cached tenants
                    foreach (var tenantGroup in service.GetUsers(Tenant.DEFAULT_TENANT, starttime).Values.GroupBy(u => u.Tenant))
                    {
                        var users = cache.Get(USERS + tenantGroup.Key) as IDictionary <Guid, UserInfo>;
                        if (users != null)
                        {
                            lock (users)
                            {
                                foreach (var u in tenantGroup)
                                {
                                    users[u.ID] = u;
                                }
                            }
                        }
                    }

                    foreach (var tenantGroup in service.GetGroups(Tenant.DEFAULT_TENANT, starttime).Values.GroupBy(g => g.Tenant))
                    {
                        var groups = cache.Get(GROUPS + tenantGroup.Key) as IDictionary <Guid, Group>;
                        if (groups != null)
                        {
                            lock (groups)
                            {
                                foreach (var g in tenantGroup)
                                {
                                    groups[g.Id] = g;
                                }
                            }
                        }
                    }

                    foreach (var tenantGroup in service.GetUserGroupRefs(Tenant.DEFAULT_TENANT, starttime).Values.GroupBy(r => r.Tenant))
                    {
                        var refs = cache.Get(REFS + tenantGroup.Key) as IDictionary <string, UserGroupRef>;
                        if (refs != null)
                        {
                            lock (refs)
                            {
                                foreach (var r in tenantGroup)
                                {
                                    refs[r.CreateKey()] = r;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    getchanges = 0;
                }
            }
        }
コード例 #15
0
        private void GetChangesFromDb()
        {
            if (!TrustInterval.Expired)
            {
                return;
            }

            if (Interlocked.CompareExchange(ref getchanges, 1, 0) == 0)
            {
                try
                {
                    if (!TrustInterval.Expired)
                    {
                        return;
                    }

                    var starttime = TrustInterval.StartTime;
                    if (starttime != default)
                    {
                        var correction = TimeSpan.FromTicks(DbExpiration.Ticks * 3);
                        starttime = TrustInterval.StartTime.Subtract(correction);
                    }

                    TrustInterval.Start(DbExpiration);

                    //get and merge changes in cached tenants
                    foreach (var tenantGroup in Service.GetUsers(Tenant.DEFAULT_TENANT, starttime).Values.GroupBy(u => u.Tenant))
                    {
                        var users = Cache.Get <IDictionary <Guid, UserInfo> >(UserServiceCache.GetUserCacheKey(tenantGroup.Key));
                        if (users != null)
                        {
                            lock (users)
                            {
                                foreach (var u in tenantGroup)
                                {
                                    users[u.ID] = u;
                                }
                            }
                        }
                    }

                    foreach (var tenantGroup in Service.GetGroups(Tenant.DEFAULT_TENANT, starttime).Values.GroupBy(g => g.Tenant))
                    {
                        var groups = Cache.Get <IDictionary <Guid, Group> >(UserServiceCache.GetGroupCacheKey(tenantGroup.Key));
                        if (groups != null)
                        {
                            lock (groups)
                            {
                                foreach (var g in tenantGroup)
                                {
                                    groups[g.Id] = g;
                                }
                            }
                        }
                    }

                    foreach (var tenantGroup in Service.GetUserGroupRefs(Tenant.DEFAULT_TENANT, starttime).Values.GroupBy(r => r.Tenant))
                    {
                        var refs = Cache.Get <UserGroupRefStore>(UserServiceCache.GetRefCacheKey(tenantGroup.Key));
                        if (refs != null)
                        {
                            lock (refs)
                            {
                                foreach (var r in tenantGroup)
                                {
                                    refs[r.CreateKey()] = r;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    Volatile.Write(ref getchanges, 0);
                }
            }
        }
コード例 #16
0
 public CachedQuotaService()
 {
     Interval        = new TrustInterval();
     CacheExpiration = TimeSpan.FromMinutes(10);
 }
コード例 #17
0
        private void GetChangesFromDb()
        {
            if (Interlocked.CompareExchange(ref getchanges, 1, 0) == 0)
            {
                try
                {
                    if (trustInterval == null)
                    {
                        trustInterval = new TrustInterval();
                        trustInterval.Start(DbExpiration);
                    }
                    if (!trustInterval.Expired) return;

                    var starttime = trustInterval.StartTime.AddMinutes(-1);
                    trustInterval.Start(DbExpiration);

                    //get and merge changes in cached tenants
                    foreach (var tenantGroup in service.GetUsers(Tenant.DEFAULT_TENANT, starttime).Values.GroupBy(u => u.Tenant))
                    {
                        var users = cache.Get(USERS + tenantGroup.Key) as IDictionary<Guid, UserInfo>;
                        if (users != null)
                        {
                            lock (users)
                            {
                                foreach (var u in tenantGroup)
                                {
                                    users[u.ID] = u;
                                }
                            }
                        }
                    }

                    foreach (var tenantGroup in service.GetGroups(Tenant.DEFAULT_TENANT, starttime).Values.GroupBy(g => g.Tenant))
                    {
                        var groups = cache.Get(GROUPS + tenantGroup.Key) as IDictionary<Guid, Group>;
                        if (groups != null)
                        {
                            lock (groups)
                            {
                                foreach (var g in tenantGroup)
                                {
                                    groups[g.Id] = g;
                                }
                            }
                        }
                    }

                    foreach (var tenantGroup in service.GetUserGroupRefs(Tenant.DEFAULT_TENANT, starttime).Values.GroupBy(r => r.Tenant))
                    {
                        var refs = cache.Get(REFS + tenantGroup.Key) as IDictionary<string, UserGroupRef>;
                        if (refs != null)
                        {
                            lock (refs)
                            {
                                foreach (var r in tenantGroup)
                                {
                                    refs[r.CreateKey()] = r;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    getchanges = 0;
                }
            }
        }