From 966d1fe6077c885db064fcea98bb48cbccb464d6 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期一, 14 十月 2024 17:23:02 +0800
Subject: [PATCH] WCS

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/Caches/SqlSugarCacheService.cs |   69 ++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 0 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Caches/SqlSugarCacheService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Caches/SqlSugarCacheService.cs"
new file mode 100644
index 0000000..4b6d04d
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Caches/SqlSugarCacheService.cs"
@@ -0,0 +1,69 @@
+锘縰sing Microsoft.Extensions.Caching.Memory;
+using SqlSugar;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WIDESEA_Core.Caches
+{
+    /// <summary>
+    /// 瀹炵幇SqlSugar鐨処CacheService鎺ュ彛
+    /// </summary>
+    public class SqlSugarCacheService : ICacheService
+    {
+        private readonly Lazy<ICaching> _caching = new(() => App.GetService<ICaching>(false));
+        private ICaching Caching => _caching.Value;
+
+        public void Add<V>(string key, V value)
+        {
+            Caching.Set(key, value);
+        }
+
+        public void Add<V>(string key, V value, int cacheDurationInSeconds)
+        {
+            Caching.Set(key, value, TimeSpan.FromSeconds(cacheDurationInSeconds));
+        }
+
+        public bool ContainsKey<V>(string key)
+        {
+            return Caching.Exists(key);
+        }
+
+        public V Get<V>(string key)
+        {
+            return Caching.Get<V>(key);
+        }
+
+        public IEnumerable<string> GetAllKey<V>()
+        {
+            return Caching.GetAllCacheKeys();
+        }
+
+        public V GetOrCreate<V>(string cacheKey, Func<V> create, int cacheDurationInSeconds = int.MaxValue)
+        {
+            if (!ContainsKey<V>(cacheKey))
+            {
+                var value = create();
+                Caching.Set(cacheKey, value, TimeSpan.FromSeconds(cacheDurationInSeconds));
+                return value;
+            }
+
+            return Caching.Get<V>(cacheKey);
+        }
+
+        public void Remove<V>(string key)
+        {
+            Caching.Remove(key);
+        }
+
+        public bool RemoveAll()
+        {
+            Caching.RemoveAll();
+            return true;
+        }
+    }
+}

--
Gitblit v1.9.3