diff --git a/Squidex.sln b/Squidex.sln index da5531380..133daf848 100644 --- a/Squidex.sln +++ b/Squidex.sln @@ -38,8 +38,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Squidex.Read.Tests", "tests EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Squidex.Infrastructure.Redis", "src\Squidex.Infrastructure.Redis\Squidex.Infrastructure.Redis.xproj", "{D7166C56-178A-4457-B56A-C615C7450DEE}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Squidex.Infrastructure.GoogleCloud", "src\Squidex.Infrastructure.GoogleCloud\Squidex.Infrastructure.GoogleCloud.xproj", "{4A80390E-507A-4477-8A10-BE89A7427232}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -98,10 +96,6 @@ Global {D7166C56-178A-4457-B56A-C615C7450DEE}.Debug|Any CPU.Build.0 = Debug|Any CPU {D7166C56-178A-4457-B56A-C615C7450DEE}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7166C56-178A-4457-B56A-C615C7450DEE}.Release|Any CPU.Build.0 = Release|Any CPU - {4A80390E-507A-4477-8A10-BE89A7427232}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4A80390E-507A-4477-8A10-BE89A7427232}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4A80390E-507A-4477-8A10-BE89A7427232}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4A80390E-507A-4477-8A10-BE89A7427232}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -119,6 +113,5 @@ Global {6A811927-3C37-430A-90F4-503E37123956} = {8CF53B92-5EB1-461D-98F8-70DA9B603FBF} {8B074219-F69A-4E41-83C6-12EE1E647779} = {4C6B06C2-6D77-4E0E-AE32-D7050236433A} {D7166C56-178A-4457-B56A-C615C7450DEE} = {8CF53B92-5EB1-461D-98F8-70DA9B603FBF} - {4A80390E-507A-4477-8A10-BE89A7427232} = {8CF53B92-5EB1-461D-98F8-70DA9B603FBF} EndGlobalSection EndGlobal diff --git a/src/Squidex.Infrastructure/Caching/IInvalidatingCache.cs b/src/Squidex.Infrastructure/Caching/IInvalidatingCache.cs new file mode 100644 index 000000000..4047b604a --- /dev/null +++ b/src/Squidex.Infrastructure/Caching/IInvalidatingCache.cs @@ -0,0 +1,15 @@ +// ========================================================================== +// IInvalidatingCache.cs +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex Group +// All rights reserved. +// ========================================================================== + +namespace Squidex.Infrastructure.Caching +{ + public interface IInvalidatingCache + { + void Invalidate(object key); + } +} diff --git a/src/Squidex.Infrastructure/Caching/InvalidatingMemoryCache.cs b/src/Squidex.Infrastructure/Caching/InvalidatingMemoryCache.cs index 0a2ea7566..cb09d2a17 100644 --- a/src/Squidex.Infrastructure/Caching/InvalidatingMemoryCache.cs +++ b/src/Squidex.Infrastructure/Caching/InvalidatingMemoryCache.cs @@ -10,7 +10,7 @@ using Microsoft.Extensions.Caching.Memory; namespace Squidex.Infrastructure.Caching { - public class InvalidatingMemoryCache : IMemoryCache + public class InvalidatingMemoryCache : IMemoryCache, IInvalidatingCache { private const string ChannelName = "CacheInvalidations"; private readonly IMemoryCache inner; @@ -34,7 +34,7 @@ namespace Squidex.Infrastructure.Caching public ICacheEntry CreateEntry(object key) { - return new WrapperCacheEntry(inner.CreateEntry(key), Invalidate); + return inner.CreateEntry(key); } public bool TryGetValue(object key, out object value) @@ -45,11 +45,9 @@ namespace Squidex.Infrastructure.Caching public void Remove(object key) { inner.Remove(key); - - Invalidate(key); } - private void Invalidate(object key) + public void Invalidate(object key) { if (key is string) { diff --git a/src/Squidex.Infrastructure/Caching/InvalidatingMemoryCacheExtensions.cs b/src/Squidex.Infrastructure/Caching/InvalidatingMemoryCacheExtensions.cs new file mode 100644 index 000000000..be37f46a5 --- /dev/null +++ b/src/Squidex.Infrastructure/Caching/InvalidatingMemoryCacheExtensions.cs @@ -0,0 +1,22 @@ +// ========================================================================== +// InvalidatingMemoryCacheExtensions.cs +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex Group +// All rights reserved. +// ========================================================================== + +using Microsoft.Extensions.Caching.Memory; + +namespace Squidex.Infrastructure.Caching +{ + public static class InvalidatingMemoryCacheExtensions + { + public static void Invalidate(this IMemoryCache cache, object key) + { + var invalidatingCache = cache as IInvalidatingCache; + + invalidatingCache?.Invalidate(key); + } + } +} diff --git a/src/Squidex.Infrastructure/Caching/WrapperCacheEntry.cs b/src/Squidex.Infrastructure/Caching/WrapperCacheEntry.cs deleted file mode 100644 index 1e41b60f4..000000000 --- a/src/Squidex.Infrastructure/Caching/WrapperCacheEntry.cs +++ /dev/null @@ -1,83 +0,0 @@ -// ========================================================================== -// WrapperCacheEntry.cs -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex Group -// All rights reserved. -// ========================================================================== - -using System; -using System.Collections.Generic; -using Microsoft.Extensions.Caching.Memory; -using Microsoft.Extensions.Primitives; - -namespace Squidex.Infrastructure.Caching -{ - internal sealed class WrapperCacheEntry : ICacheEntry - { - private readonly ICacheEntry inner; - private readonly Action invalidator; - - public object Key - { - get { return inner.Key; } - } - - public IList ExpirationTokens - { - get { return inner.ExpirationTokens; } - } - - public IList PostEvictionCallbacks - { - get { return inner.PostEvictionCallbacks; } - } - - public DateTimeOffset? AbsoluteExpiration - { - get { return inner.AbsoluteExpiration; } - set { inner.AbsoluteExpiration = value; } - } - - public TimeSpan? AbsoluteExpirationRelativeToNow - { - get { return inner.AbsoluteExpirationRelativeToNow; } - set { inner.AbsoluteExpirationRelativeToNow = value; } - } - - public TimeSpan? SlidingExpiration - { - get { return inner.SlidingExpiration; } - set { inner.SlidingExpiration = value; } - } - - public CacheItemPriority Priority - { - get { return inner.Priority; } - set { inner.Priority = value; } - } - - public object Value - { - get { return inner.Value; } - set { inner.Value = value; } - } - - public WrapperCacheEntry(ICacheEntry inner, Action invalidator) - { - this.inner = inner; - - this.invalidator = invalidator; - } - - public void Dispose() - { - if (Key is string) - { - invalidator(Key); - } - - inner.Dispose(); - } - } -} diff --git a/src/Squidex.Read/Apps/Services/Implementations/CachingAppProvider.cs b/src/Squidex.Read/Apps/Services/Implementations/CachingAppProvider.cs index ee1e90829..644289010 100644 --- a/src/Squidex.Read/Apps/Services/Implementations/CachingAppProvider.cs +++ b/src/Squidex.Read/Apps/Services/Implementations/CachingAppProvider.cs @@ -10,6 +10,7 @@ using System; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Memory; using Squidex.Infrastructure; +using Squidex.Infrastructure.Caching; using Squidex.Read.Apps.Repositories; using Squidex.Read.Utils; @@ -76,8 +77,14 @@ namespace Squidex.Read.Apps.Services.Implementations public void Remove(NamedId id) { - Cache.Remove(BuildIdCacheKey(id.Id)); - Cache.Remove(BuildNameCacheKey(id.Name)); + var cacheKeyById = BuildIdCacheKey(id.Id); + var cacheKeyByName = BuildNameCacheKey(id.Name); + + Cache.Remove(cacheKeyById); + Cache.Remove(cacheKeyByName); + + Cache.Invalidate(cacheKeyById); + Cache.Invalidate(cacheKeyByName); } private static string BuildNameCacheKey(string name) diff --git a/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs b/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs index e2a2c8bff..6899bc874 100644 --- a/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs +++ b/src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs @@ -10,6 +10,7 @@ using System; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Memory; using Squidex.Infrastructure; +using Squidex.Infrastructure.Caching; using Squidex.Read.Schemas.Repositories; using Squidex.Read.Utils; @@ -77,8 +78,14 @@ namespace Squidex.Read.Schemas.Services.Implementations public void Remove(NamedId appId, NamedId schemaId) { - Cache.Remove(BuildIdCacheKey(schemaId.Id)); - Cache.Remove(BuildNameCacheKey(appId.Id, schemaId.Name)); + var cacheKeyById = BuildIdCacheKey(schemaId.Id); + var cacheKeyByName = BuildNameCacheKey(appId.Id, schemaId.Name); + + Cache.Remove(cacheKeyById); + Cache.Remove(cacheKeyByName); + + Cache.Invalidate(cacheKeyById); + Cache.Invalidate(cacheKeyByName); } private static string BuildNameCacheKey(Guid appId, string name) diff --git a/src/Squidex/Config/Domain/ClusterModule.cs b/src/Squidex/Config/Domain/ClusterModule.cs index c957df007..9b4d4f090 100644 --- a/src/Squidex/Config/Domain/ClusterModule.cs +++ b/src/Squidex/Config/Domain/ClusterModule.cs @@ -8,11 +8,9 @@ using System; using Autofac; -using Google.Cloud.PubSub.V1; using Microsoft.Extensions.Configuration; using Squidex.Infrastructure; using Squidex.Infrastructure.CQRS.Events; -using Squidex.Infrastructure.GoogleCloud; using Squidex.Infrastructure.Redis; using StackExchange.Redis; @@ -72,25 +70,6 @@ namespace Squidex.Config.Domain .As() .SingleInstance(); } - else if (string.Equals(clustererType, "GCE", StringComparison.OrdinalIgnoreCase)) - { - var projectId = Configuration.GetValue("squidex:clusterer:gce:projectId"); - - if (string.IsNullOrWhiteSpace(projectId)) - { - throw new ConfigurationException("You must specify the Google cloud engine project id in the 'squidex:clusterer:gce:projectId' configuration section."); - } - - builder.RegisterInstance(new ProjectName(projectId)) - .AsSelf() - .SingleInstance(); - - builder.RegisterType() - .As() - .As() - .SingleInstance(); - - } else if (string.Equals(clustererType, "None", StringComparison.OrdinalIgnoreCase)) { builder.RegisterType() diff --git a/src/Squidex/Properties/launchSettings.json b/src/Squidex/Properties/launchSettings.json index 0bb6a0c3a..1aa5504bd 100644 --- a/src/Squidex/Properties/launchSettings.json +++ b/src/Squidex/Properties/launchSettings.json @@ -18,9 +18,7 @@ "commandName": "Project", "launchUrl": "http://localhost:5000", "environmentVariables": { - "SQUIDEX__CLUSTERER__GCE__PROJECTID": "squidex-157415", - "ASPNETCORE_ENVIRONMENT": "Development", - "SQUIDEX__CLUSTERER__TYPE": "gce" + "ASPNETCORE_ENVIRONMENT": "Development" } } }