Browse Source

补偿get-blobsize Redis缓存

CrazyIter_Bin 4 years ago
parent
commit
c3d345d0fd
1 changed files with 13 additions and 0 deletions
  1. 13 0
      TEAMModelOS/Controllers/Core/BlobController.cs

+ 13 - 0
TEAMModelOS/Controllers/Core/BlobController.cs

@@ -16,6 +16,7 @@ using TEAMModelOS.SDK.Extension;
 using System.IdentityModel.Tokens.Jwt;
 using Microsoft.AspNetCore.Authorization;
 using TEAMModelOS.Filter;
+using StackExchange.Redis;
 
 namespace TEAMModelOS.Controllers.Core
 {
@@ -233,10 +234,22 @@ namespace TEAMModelOS.Controllers.Core
         [HttpPost("get-blobsize")]
         public async Task<ActionResult> GetBlobsSize(JsonElement request)
         {
+            
             request.TryGetProperty("containerName", out JsonElement containerName);
             var name =containerName.GetString();
+            RedisValue value = default;
+            value = _azureRedis.GetRedisClient(8).HashGet($"Blob:Record", name);
+            if (value != default && !value.IsNullOrEmpty)
+            {
+                JsonElement record = value.ToString().ToObject<JsonElement>();
+                if (record.TryGetInt64(out long blobsize))
+                {
+                    return Ok(new { size= blobsize });
+                }
+            }
             var client = _azureStorage.GetBlobContainerClient(name);
             var size = await client.GetBlobsSize();
+            await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", name, size);
             return Ok(new { size });
         }
         /// <summary>