Esempio n. 1
0
        public async Task <ISchemaEntity?> GetSchemaAsync(DomainId appId, string name, bool canCache,
                                                          CancellationToken ct = default)
        {
            using (Telemetry.Activities.StartActivity("SchemasIndex/GetSchemaByNameAsync"))
            {
                var cacheKey = GetCacheKey(appId, name);

                if (canCache)
                {
                    if (grainCache.TryGetValue(cacheKey, out var value) && value is ISchemaEntity cachedSchema)
                    {
                        return(cachedSchema);
                    }
                }

                var id = await GetSchemaIdAsync(appId, name);

                if (id == DomainId.Empty)
                {
                    return(null);
                }

                return(await GetSchemaAsync(appId, id, canCache, ct));
            }
        }
Esempio n. 2
0
        private static void AssertCache(IReplicatedCache cache, string key, object?expectedValue, bool expectedFound)
        {
            var found = cache.TryGetValue(key, out var value);

            Assert.Equal(expectedFound, found);
            Assert.Equal(expectedValue, value);
        }
Esempio n. 3
0
        public Task <App?> GetCachedAsync(string id, CancellationToken ct = default)
        {
            Guard.NotNullOrEmpty(id, nameof(id));

            if (cache.TryGetValue(id, out var temp) && temp is App app)
            {
                return(Task.FromResult <App?>(app));
            }

            return(GetAsync(id, ct));
        }
Esempio n. 4
0
        public async Task <IAppEntity?> GetAppByNameAsync(string name, bool canCache = false)
        {
            using (Profiler.TraceMethod <AppsIndex>())
            {
                if (canCache)
                {
                    if (grainCache.TryGetValue(GetCacheKey(name), out var v) && v is IAppEntity cacheApp)
                    {
                        return(cacheApp);
                    }
                }

                var appId = await GetAppIdAsync(name);

                if (appId == DomainId.Empty)
                {
                    return(null);
                }

                return(await GetAppAsync(appId, canCache));
            }
        }
Esempio n. 5
0
        public async Task <IAppEntity?> GetAppAsync(string name, bool canCache = false,
                                                    CancellationToken ct       = default)
        {
            using (Telemetry.Activities.StartActivity("AppProvider/GetAppByNameAsync"))
            {
                if (canCache)
                {
                    if (grainCache.TryGetValue(GetCacheKey(name), out var v) && v is IAppEntity cacheApp)
                    {
                        return(cacheApp);
                    }
                }

                var appId = await GetAppIdAsync(name);

                if (appId == DomainId.Empty)
                {
                    return(null);
                }

                return(await GetAppAsync(appId, canCache, ct));
            }
        }
Esempio n. 6
0
            public async Task <Guid> GetValueAsync()
            {
                if (cache.TryGetValue("KEY", out var cached) && cached is Guid guid)
                {
                    return(guid);
                }

                await Task.Delay(1);

                guid = sharedValue;

                await cache.AddAsync("KEY", guid, TimeSpan.FromSeconds(10));

                return(guid);
            }
Esempio n. 7
0
        public async Task <ISchemaEntity?> GetSchemaByNameAsync(DomainId appId, string name, bool canCache)
        {
            using (Profiler.TraceMethod <SchemasIndex>())
            {
                var cacheKey = GetCacheKey(appId, name);

                if (canCache)
                {
                    if (grainCache.TryGetValue(cacheKey, out var v) && v is ISchemaEntity cachedSchema)
                    {
                        return(cachedSchema);
                    }
                }

                var id = await GetSchemaIdAsync(appId, name);

                if (id == DomainId.Empty)
                {
                    return(null);
                }

                return(await GetSchemaAsync(appId, id, canCache));
            }
        }