From df54494f62bb0ed076b314dfd231c16b2c02f951 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Mon, 4 Sep 2017 08:08:07 +0200 Subject: [PATCH] Caching fixes. --- .../Contents/GraphQL/CachingGraphQLService.cs | 3 ++- .../Implementations/CachingSchemaProvider.cs | 22 +++---------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/Squidex.Domain.Apps.Read/Contents/GraphQL/CachingGraphQLService.cs b/src/Squidex.Domain.Apps.Read/Contents/GraphQL/CachingGraphQLService.cs index 7e4fe2026..595082711 100644 --- a/src/Squidex.Domain.Apps.Read/Contents/GraphQL/CachingGraphQLService.cs +++ b/src/Squidex.Domain.Apps.Read/Contents/GraphQL/CachingGraphQLService.cs @@ -29,6 +29,7 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL { public sealed class CachingGraphQLService : CachingProviderBase, IGraphQLService, IEventConsumer { + private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(60); private readonly IContentRepository contentRepository; private readonly IGraphQLUrlGenerator urlGenerator; private readonly IAssetRepository assetRepository; @@ -108,7 +109,7 @@ namespace Squidex.Domain.Apps.Read.Contents.GraphQL modelContext = new GraphQLModel(app, allSchemas.Where(x => x.IsPublished), urlGenerator); - Cache.Set(cacheKey, modelContext); + Cache.Set(cacheKey, modelContext, CacheDuration); } return modelContext; diff --git a/src/Squidex.Domain.Apps.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs b/src/Squidex.Domain.Apps.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs index ea46a0914..da189ecda 100644 --- a/src/Squidex.Domain.Apps.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs +++ b/src/Squidex.Domain.Apps.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs @@ -9,7 +9,7 @@ using System; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Memory; -using Squidex.Domain.Apps.Events.Schemas; +using Squidex.Domain.Apps.Events; using Squidex.Domain.Apps.Read.Schemas.Repositories; using Squidex.Domain.Apps.Read.Utils; using Squidex.Infrastructure; @@ -110,25 +110,9 @@ namespace Squidex.Domain.Apps.Read.Schemas.Services.Implementations Cache.Invalidate(cacheKeyByName); } - if (@event.Payload is FieldEvent fieldEvent) + if (@event.Payload is SchemaEvent schemaEvent) { - Remove(fieldEvent.AppId, fieldEvent.SchemaId); - } - else if (@event.Payload is SchemaCreated schemaCreatedEvent) - { - Remove(schemaCreatedEvent.AppId, schemaCreatedEvent.SchemaId); - } - else if (@event.Payload is SchemaDeleted schemaDeletedEvent) - { - Remove(schemaDeletedEvent.AppId, schemaDeletedEvent.SchemaId); - } - else if (@event.Payload is SchemaUpdated schemaUpdatedEvent) - { - Remove(schemaUpdatedEvent.AppId, schemaUpdatedEvent.SchemaId); - } - else if (@event.Payload is ScriptsConfigured scriptsConfiguredEvent) - { - Remove(scriptsConfiguredEvent.AppId, scriptsConfiguredEvent.SchemaId); + Remove(schemaEvent.AppId, schemaEvent.SchemaId); } return TaskHelper.Done;