Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions EasyCaching.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.CSRedis", "src\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Bus.CSRedis", "src\EasyCaching.Bus.CSRedis\EasyCaching.Bus.CSRedis.csproj", "{861E5373-BEF6-4AA2-92C7-8F4941A079E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyCaching.Disk", "src\EasyCaching.Disk\EasyCaching.Disk.csproj", "{3D48FD75-01D6-44F9-B7C3-CB6DE784F476}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -139,6 +141,10 @@ Global
{861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{861E5373-BEF6-4AA2-92C7-8F4941A079E7}.Release|Any CPU.Build.0 = Release|Any CPU
{3D48FD75-01D6-44F9-B7C3-CB6DE784F476}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D48FD75-01D6-44F9-B7C3-CB6DE784F476}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D48FD75-01D6-44F9-B7C3-CB6DE784F476}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D48FD75-01D6-44F9-B7C3-CB6DE784F476}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CE61FAA2-0233-451C-991D-4222ED61C84B} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
Expand All @@ -162,5 +168,6 @@ Global
{6EBE36A2-F128-4C63-B90A-B700D8C2F2E8} = {EBB55F65-7D07-4281-8D5E-7B0CA88E1AD0}
{6584761E-E51C-408F-BE51-CA0F6269589B} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
{861E5373-BEF6-4AA2-92C7-8F4941A079E7} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
{3D48FD75-01D6-44F9-B7C3-CB6DE784F476} = {A0F5CC7E-155F-4726-8DEB-E966950B3FE9}
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions build/releasenotes.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@
<EasyCachingRabbitBusPackageNotes>
1. Upgrading dependencies.
</EasyCachingRabbitBusPackageNotes>
<EasyCachingDiskPackageNotes>
1. init.
</EasyCachingDiskPackageNotes>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions build/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
<EasyCachingRedisBusPackageVersion>0.5.6</EasyCachingRedisBusPackageVersion>
<EasyCachingCSRedisBusPackageVersion>0.5.6</EasyCachingCSRedisBusPackageVersion>
<EasyCachingRabbitBusPackageVersion>0.5.6</EasyCachingRabbitBusPackageVersion>
<EasyCachingDiskPackageVersion>0.5.6</EasyCachingDiskPackageVersion>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/EasyCaching.Core/Internal/CachingProviderType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum CachingProviderType
Memcached,
Redis,
SQLite,
Disk,
Ext1,
Ext2
}
Expand Down
10 changes: 10 additions & 0 deletions src/EasyCaching.Core/Internal/EasyCachingConstValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class EasyCachingConstValue
/// </summary>
public const string InMemorySection = "easycaching:inmemory";

/// <summary>
/// The disk section.
/// </summary>
public const string DiskSection = "easycaching:disk";

/// <summary>
/// The redis bus section.
/// </summary>
Expand Down Expand Up @@ -70,6 +75,11 @@ public class EasyCachingConstValue
/// </summary>
public const string DefaultSQLiteName = "DefaultSQLite";

/// <summary>
/// The default name of the disk.
/// </summary>
public const string DefaultDiskName = "DefaultDisk";

/// <summary>
/// The default name of the serializer.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions src/EasyCaching.Disk/Configurations/DiskOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace EasyCaching.Disk
{
using EasyCaching.Core.Configurations;

public class DiskOptions : BaseProviderOptions
{
public DiskOptions()
{
}

public DiskDbOptions DBConfig { get; set; } = new DiskDbOptions();
}
}
49 changes: 49 additions & 0 deletions src/EasyCaching.Disk/Configurations/DiskOptionsExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace EasyCaching.Disk
{
using System;
using EasyCaching.Core;
using EasyCaching.Core.Configurations;
using MessagePack.Resolvers;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

internal sealed class DiskOptionsExtension : IEasyCachingOptionsExtension
{
/// <summary>
/// The name.
/// </summary>
private readonly string _name;
/// <summary>
/// The configure.
/// </summary>
private readonly Action<DiskOptions> configure;

public DiskOptionsExtension(string name, Action<DiskOptions> configure)
{
this._name = name;
this.configure = configure;
}

public void AddServices(IServiceCollection services)
{
services.AddOptions();
services.Configure(_name, configure);

services.TryAddSingleton<IEasyCachingProviderFactory, DefaultEasyCachingProviderFactory>();
services.AddSingleton<IEasyCachingProvider, DefaultDiskCachingProvider>(x =>
{
var optionsMon = x.GetRequiredService<Microsoft.Extensions.Options.IOptionsMonitor<DiskOptions>>();
var options = optionsMon.Get(_name);
//ILoggerFactory can be null
var factory = x.GetService<Microsoft.Extensions.Logging.ILoggerFactory>();
return new DefaultDiskCachingProvider(_name, options, factory);
});
}

public void WithServices(IApplicationBuilder app)
{
// Method intentionally left empty.
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace EasyCaching.Disk
{
using System;
using EasyCaching.Core;
using EasyCaching.Core.Configurations;
using Microsoft.Extensions.Configuration;

public static class EasyCachingOptionsExtensions
{
/// <summary>
/// Uses the disk caching provider.
/// </summary>
/// <param name="options">Options.</param>
/// <param name="configure">Configure.</param>
/// <param name="name">Name.</param>
public static EasyCachingOptions UseDisk(this EasyCachingOptions options, Action<DiskOptions> configure, string name = EasyCachingConstValue.DefaultDiskName)
{
ArgumentCheck.NotNull(configure, nameof(configure));

options.RegisterExtension(new DiskOptionsExtension(name, configure));

return options;
}

public static EasyCachingOptions UseDisk(this EasyCachingOptions options, IConfiguration configuration, string name = EasyCachingConstValue.DefaultDiskName, string sectionName = EasyCachingConstValue.DiskSection)
{
var dbConfig = configuration.GetSection(sectionName);
var diskOptions = new DiskOptions();
dbConfig.Bind(diskOptions);

void configure(DiskOptions x)
{
x.EnableLogging = diskOptions.EnableLogging;
x.MaxRdSecond = diskOptions.MaxRdSecond;
x.DBConfig = diskOptions.DBConfig;
}
return options.UseDisk(configure, name);
}
}
}
Loading