Skip to content

Commit

Permalink
使用Qiniu nuget包
Browse files Browse the repository at this point in the history
  • Loading branch information
withsalt committed Mar 4, 2022
1 parent 85c58ae commit e83e589
Show file tree
Hide file tree
Showing 77 changed files with 54 additions and 9,526 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public async Task<IActionResult> ListBuckets()
| SessionToken | string | token | | 仅Minio中使用 |
| IsEnableHttps | bool | 是否启用HTTPS | true | 建议启用 |
| IsEnableCache | bool | 是否启用缓存 | true | 启用后将缓存签名URL,以减少请求次数 |
| UseCustumCacheProvider | bool | 是否使用自定义缓存提供器 | false | 将用自己实现的缓存提供器替代内部的MemoryCache,如使用Redis |

### API参考

Expand Down Expand Up @@ -328,12 +329,62 @@ Task<ItemMeta> GetObjectMetadataAsync(string bucketName
清除该对象的访问权限或将其恢复至继承权限。
注意:七牛云对象储存不支持此操作!

### 替换内部缓存提供器

如果启用了缓存来缓存签名URL,可以提高单个文件的签名URL请求效率。由于1.1.3之前版本使用的MemoryCache,有三个问题:
1、不支持分布式,只能单机缓存
2、大量占用应用服务器内存
3、应用重启之后,之前的缓存丢失

从1.1.3开始,提供了一个ICacheProvider接口。用户可以自己实现此接口,替换掉内部的MemoryCache,比如使用Redis。
下面是代码:
```csharp
class RedisCacheProvider : ICacheProvider
{
private readonly RedisClient _cache;

public RedisCacheProvider(RedisClient cache)
{
this._cache = cache ?? throw new ArgumentNullException(nameof(cache));
}

public T Get<T>(string key) where T : class
{
string val = _cache.Get(key);
if (string.IsNullOrEmpty(val))
{
return default(T);
}
return JsonUtil.DeserializeStringToObject<T>(val);
}

public void Remove(string key)
{
_cache.Del(key);
}

public void Set<T>(string key, T value, TimeSpan ts) where T : class
{
string stringVal = JsonUtil.SerializeToString(value);
_cache.Set(key, stringVal, ts);
}
}

//然后在ConfigureServices中注入
var client = new RedisClient("127.0.0.1:6379,password=,ConnectTimeout=3000,defaultdatabase=0");
services.TryAddSingleton<RedisClient>(client);
services.TryAddSingleton<ICacheProvider, RedisCacheProvider>();
```

## Dependencies

1. Aliyun.OSS.SDK.NetCore
2. Microsoft.Extensions.Caching.Memory
3. Newtonsoft.Json
4. Tencent.QCloud.Cos.Sdk
5. Minio
6. Qiniu
7. https://github.com/huaweicloud/huaweicloud-sdk-dotnet-obs

## To do list
1. 修改签名URL过期策略为滑动过期策略
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using FreeRedis;
using Microsoft.Extensions.Caching.Memory;
using OnceMi.AspNetCore.OSS;
using OnceMi.Framework.Util.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Sample.AspNetCore.Mvc.CacheProviders
{
Expand Down
5 changes: 2 additions & 3 deletions src/samples/Sample.AspNetCore.Mvc/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ public void ConfigureServices(IServiceCollection services)
option.IsEnableHttps = true;
option.IsEnableCache = true;

//是否是否使用自定义缓存提供器
//如果启用此项配置,将使用自定义的缓存提供器替换默认的MemoryCache
//前提是如上面代码所示,实现了自己缓存提供器
//是否使用自定义缓存提供器
//启用此项配置的前提是如上面代码所示,实现了自己缓存提供器
option.UseCustumCacheProvider = false;
});

Expand Down
1 change: 1 addition & 0 deletions src/src/OnceMi.AspNetCore.OSS/OnceMi.AspNetCore.OSS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Minio" Version="4.0.0" />
<PackageReference Include="Qiniu" Version="8.0.0" />
<PackageReference Include="Tencent.QCloud.Cos.Sdk" Version="5.4.28" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
Expand Down
77 changes: 0 additions & 77 deletions src/src/OnceMi.AspNetCore.OSS/SDK/Qiniu/CDN/BandwidthInfo.cs

This file was deleted.

68 changes: 0 additions & 68 deletions src/src/OnceMi.AspNetCore.OSS/SDK/Qiniu/CDN/BandwidthRequest.cs

This file was deleted.

98 changes: 0 additions & 98 deletions src/src/OnceMi.AspNetCore.OSS/SDK/Qiniu/CDN/BandwidthResult.cs

This file was deleted.

Loading

0 comments on commit e83e589

Please sign in to comment.