|
|
|
@ -4,6 +4,8 @@ using Microsoft.Extensions.Caching.Distributed;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
|
using Volo.Abp.Caching;
|
|
|
|
|
using Volo.Abp.Json.SystemTextJson;
|
|
|
|
|
using Volo.Abp.Json.SystemTextJson.Modifiers;
|
|
|
|
|
|
|
|
|
|
namespace Volo.Abp.Domain.Entities.Caching;
|
|
|
|
|
|
|
|
|
@ -11,7 +13,7 @@ public static class EntityCacheServiceCollectionExtensions
|
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection AddEntityCache<TEntity, TKey>(
|
|
|
|
|
this IServiceCollection services,
|
|
|
|
|
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
|
|
|
|
|
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
|
|
|
|
|
where TEntity : Entity<TKey>
|
|
|
|
|
{
|
|
|
|
|
services
|
|
|
|
@ -21,18 +23,23 @@ public static class EntityCacheServiceCollectionExtensions
|
|
|
|
|
>();
|
|
|
|
|
services
|
|
|
|
|
.TryAddTransient<EntityCacheWithoutCacheItem<TEntity, TKey>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services.Configure<AbpDistributedCacheOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.ConfigureCache<TEntity>(cacheOptions ?? GetDefaultCacheOptions());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services.Configure<AbpSystemTextJsonSerializerModifiersOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Modifiers.Add(new AbpIncludeNonPublicPropertiesModifiers<TEntity, TKey>().CreateModifyAction(x => x.Id));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static IServiceCollection AddEntityCache<TEntity, TEntityCacheItem, TKey>(
|
|
|
|
|
this IServiceCollection services,
|
|
|
|
|
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
|
|
|
|
|
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
|
|
|
|
|
where TEntity : Entity<TKey>
|
|
|
|
|
where TEntityCacheItem : class
|
|
|
|
|
{
|
|
|
|
@ -43,18 +50,18 @@ public static class EntityCacheServiceCollectionExtensions
|
|
|
|
|
>();
|
|
|
|
|
services
|
|
|
|
|
.TryAddTransient<EntityCacheWithObjectMapper<TEntity, TEntityCacheItem, TKey>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services.Configure<AbpDistributedCacheOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.ConfigureCache<TEntityCacheItem>(cacheOptions ?? GetDefaultCacheOptions());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IServiceCollection AddEntityCache<TObjectMapperContext, TEntity, TEntityCacheItem, TKey>(
|
|
|
|
|
this IServiceCollection services,
|
|
|
|
|
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
|
|
|
|
|
[CanBeNull] DistributedCacheEntryOptions cacheOptions = null)
|
|
|
|
|
where TEntity : Entity<TKey>
|
|
|
|
|
where TEntityCacheItem : class
|
|
|
|
|
{
|
|
|
|
@ -64,12 +71,12 @@ public static class EntityCacheServiceCollectionExtensions
|
|
|
|
|
EntityCacheWithObjectMapperContext<TObjectMapperContext, TEntity, TEntityCacheItem, TKey>
|
|
|
|
|
>();
|
|
|
|
|
services.TryAddTransient<EntityCacheWithObjectMapperContext<TObjectMapperContext, TEntity, TEntityCacheItem, TKey>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
services.Configure<AbpDistributedCacheOptions>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.ConfigureCache<TEntityCacheItem>(cacheOptions ?? GetDefaultCacheOptions());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -79,4 +86,4 @@ public static class EntityCacheServiceCollectionExtensions
|
|
|
|
|
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(2)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|