mirror of https://github.com/Squidex/squidex.git
9 changed files with 59 additions and 123 deletions
@ -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); |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue