src/DotNetCommon.Core/Cache/CacheExtensions.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

//using Microsoft.Extensions.Primitives;
//using System;
//using System.Collections.Generic;
//using System.Text;
//using System.Threading.Tasks;
//
//namespace DotNetCommon.Cache
//{
//    internal static class CacheExtensions
//    {
//        public static object Get(this IMemoryCache cache, object key)
//        {
//            cache.TryGetValue(key, out object value);
//            return value;
//        }
//
//        public static TItem Get<TItem>(this IMemoryCache cache, object key)
//        {
//            return (TItem)(cache.Get(key) ?? default(TItem));
//        }
//
//        public static bool TryGetValue<TItem>(this IMemoryCache cache, object key, out TItem value)
//        {
//            if (cache.TryGetValue(key, out object result))
//            {
//                if (result == null)
//                {
//                    value = default;
//                    return true;
//                }
//
//                if (result is TItem item)
//                {
//                    value = item;
//                    return true;
//                }
//            }
//
//            value = default;
//            return false;
//        }
//
//        public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value)
//        {
//            using ICacheEntry entry = cache.CreateEntry(key);
//            entry.Value = value;
//
//            return value;
//        }
//
//        public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, DateTimeOffset absoluteExpiration)
//        {
//            using ICacheEntry entry = cache.CreateEntry(key);
//            entry.AbsoluteExpiration = absoluteExpiration;
//            entry.Value = value;
//
//            return value;
//        }
//
//        public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, TimeSpan absoluteExpirationRelativeToNow)
后面还有 57 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。