Browse Source

Invalidating changed

pull/1/head
Sebastian 9 years ago
parent
commit
cddcf11911
  1. 7
      Squidex.sln
  2. 15
      src/Squidex.Infrastructure/Caching/IInvalidatingCache.cs
  3. 8
      src/Squidex.Infrastructure/Caching/InvalidatingMemoryCache.cs
  4. 22
      src/Squidex.Infrastructure/Caching/InvalidatingMemoryCacheExtensions.cs
  5. 83
      src/Squidex.Infrastructure/Caching/WrapperCacheEntry.cs
  6. 11
      src/Squidex.Read/Apps/Services/Implementations/CachingAppProvider.cs
  7. 11
      src/Squidex.Read/Schemas/Services/Implementations/CachingSchemaProvider.cs
  8. 21
      src/Squidex/Config/Domain/ClusterModule.cs
  9. 4
      src/Squidex/Properties/launchSettings.json

7
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

15
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);
}
}

8
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)
{

22
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);
}
}
}

83
src/Squidex.Infrastructure/Caching/WrapperCacheEntry.cs

@ -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<object> invalidator;
public object Key
{
get { return inner.Key; }
}
public IList<IChangeToken> ExpirationTokens
{
get { return inner.ExpirationTokens; }
}
public IList<PostEvictionCallbackRegistration> 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<object> invalidator)
{
this.inner = inner;
this.invalidator = invalidator;
}
public void Dispose()
{
if (Key is string)
{
invalidator(Key);
}
inner.Dispose();
}
}
}

11
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<Guid> 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)

11
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<Guid> appId, NamedId<Guid> 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)

21
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<IExternalSystem>()
.SingleInstance();
}
else if (string.Equals(clustererType, "GCE", StringComparison.OrdinalIgnoreCase))
{
var projectId = Configuration.GetValue<string>("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<GoogleCloudPubSub>()
.As<IPubSub>()
.As<IExternalSystem>()
.SingleInstance();
}
else if (string.Equals(clustererType, "None", StringComparison.OrdinalIgnoreCase))
{
builder.RegisterType<InMemoryPubSub>()

4
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"
}
}
}

Loading…
Cancel
Save