mirror of https://github.com/abpframework/abp.git
4 changed files with 75 additions and 12 deletions
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public interface IBlogFeatureCacheManager |
|||
{ |
|||
Task<BlogFeatureDto> AddOrGetAsync(Guid blogId, string featureName, Func<Task<BlogFeatureDto>> factory); |
|||
Task ClearAsync(Guid blogId, string featureName); |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
using JetBrains.Annotations; |
|||
using Microsoft.Extensions.Caching.Distributed; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeatureCacheManager : IBlogFeatureCacheManager, ITransientDependency |
|||
{ |
|||
protected IDistributedCache<BlogFeatureDto> Cache { get; } |
|||
|
|||
public BlogFeatureCacheManager(IDistributedCache<BlogFeatureDto> cache) |
|||
{ |
|||
Cache = cache; |
|||
} |
|||
|
|||
public async Task<BlogFeatureDto> AddOrGetAsync(Guid blogId, string featureName, Func<Task<BlogFeatureDto>> factory) |
|||
{ |
|||
return await Cache.GetOrAddAsync( |
|||
GetCacheKey(blogId, featureName), |
|||
factory, |
|||
() => new DistributedCacheEntryOptions |
|||
{ |
|||
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1) |
|||
}); |
|||
} |
|||
|
|||
public Task ClearAsync(Guid blogId, string featureName) |
|||
{ |
|||
return Cache.RemoveAsync(GetCacheKey(blogId, featureName)); |
|||
} |
|||
|
|||
private string GetCacheKey(Guid blogId, [NotNull] string featureName) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(featureName, nameof(featureName)); |
|||
|
|||
return $"{blogId}_{featureName}"; |
|||
} |
|||
} |
|||
} |
|||
@ -1,4 +1,8 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.EventBus; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
Loading…
Reference in new issue