Robo.Caches 1.0.0.1

dotnet add package Robo.Caches --version 1.0.0.1
                    
NuGet\Install-Package Robo.Caches -Version 1.0.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Robo.Caches" Version="1.0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Robo.Caches" Version="1.0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Robo.Caches" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Robo.Caches --version 1.0.0.1
                    
#r "nuget: Robo.Caches, 1.0.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Robo.Caches@1.0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Robo.Caches&version=1.0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Robo.Caches&version=1.0.0.1
                    
Install as a Cake Tool

robo-caches

快速开始

redis配置

在appsettings.json中加入配置信息。

"RedisCaching": { //Redis服务器配置
    "HostName": "Redis服务主机名或IP地址",
    "Port": "6379",
    "Password": "root"
  }
新建RedisSetup类
public static class RedisSetup
{
    public static void AddRedisSetup(this IServiceCollection services, IConfiguration configuration)
    {
        services.AddCaches(x =>
        {
            //  获取redis配置
            var redisOptions = configuration.GetSection("RedisCaching").Get<RedisOptions>() ?? throw new ArgumentNullException(nameof(RedisOptions));

            x.HostName = redisOptions.HostName;
            x.Port = redisOptions.Port;
            x.Password = redisOptions.Password;
        });
    }
}
依赖注入

添加到ConfigureServices依赖注入容器,如下:

public void ConfigureServices(IServiceCollection services,IConfiguration Configuration)
{
    services.AddRedisSetup(Configuration);
}
使用

在 Controller 中注入 IRedisCacheManager 然后使用 IRedisCacheManager 进行Redis的使用。

[ApiController]
[Route("[controller]")]
public class RedisController : ControllerBase
{
    private readonly IRedisCacheManager _cache;

    public RedisController(IRedisCacheManager cache)
    {
        _cache = cache;
    }

    [HttpGet]
    public IActionResult Set()
    {
        var key = nameof(RedisController);
        var except = "Robo";
        _cache.Set(key, except, TimeSpan.FromSeconds(60));
        return Ok(_cache.GetValue(key));
    }
}

详细配置

//你需要添加如下Redis 配置:
services.AddCaches(x =>
{
    //HostName,Port,Password 配置必填
    x.HostName = "localhost"; //必填项,Redis服务主机名或IP地址
    x.Port = 6379; //必填项,Redis服务端口号
    x.Password = "root"; //必填项,Redis服务密码
    //配置非必填
    x.DefaultDatabase = ""; //选填,默认数据库名
    x.SSL = false; //是否开启加密传输,默认为False
    x.WriteBuffer = 10240; //异步方法写入缓冲区大小(字节)
    x.ExpireSeconds = 60; //统一设置缓存过期时间,默认为60S
    x.ConnectRetry = 0; //执行命令出错,尝试重试的次数
    x.ClientName = ""; //连接名称,可以使用 Client List 命令查看
    x.Prefix = ""; //key前辍,所有方法都会附带此前辍,Set(prefix + "key", 111);
    x.EnvName = ""; //环境名称
});
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0.1 434 3/20/2023
1.0.0 325 2/24/2023