Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加全局缓存工厂 #1824

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

hyzx86
Copy link
Contributor

@hyzx86 hyzx86 commented Jun 8, 2024

为全局static 缓存对象 增加 缓存工厂,

由于缓存太多,可能某些需要缓存的对象未包含在内,目前已处理仓库中所有静态 ConcurrentDictionary 集合
如果有遗漏的其他类型需要缓存可以直接将初始化方式改为如下方式

    internal static ConcurrentDictionary<Guid, CustomAdapter> _dicCustomAdater = Utils.GlobalCacheFactory.CreateCacheItem<ConcurrentDictionary<Guid, CustomAdapter>>();

// 或
    internal static ConcurrentDictionary<Guid, CustomAdapter> _dicCustomAdater = Utils.GlobalCacheFactory.CreateCacheItem(new ConcurrentDictionary<Guid, CustomAdapter>);

为 Utils 类 增加抽象属性 GlobalCacheFactory

    public interface IGlobalCacheFactory
    {
        T CreateCacheItem<T>(T defaultValue = null) where T : class, new();
        T CreateCacheItem<T>() where T : new();
    }

默认实现 DefaultCacheFactory , 逻辑上保留默认初始化方式

    public class DefaultCacheFactory : IGlobalCacheFactory
    {
        public T CreateCacheItem<T>(T defaultValue = null) where T : class, new()
        {
            return defaultValue ?? new T();
        }

        public T CreateCacheItem<T>() where T : new()
        {
            return new T();
        }
    }

@hyzx86 hyzx86 marked this pull request as draft June 14, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant