Exemplo n.º 1
0
        public TEntity Find(params object[] keys)
        {
            string key    = EntityKeyInfo.CreateKeyCode(keys);
            var    entity = cacheManager.Get <TEntity>(key, Region);

            return(entity);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 尝试取缓存项,若不存在则自动加载
        /// </summary>
        /// <param name="groupKey"></param>
        /// <param name="isAutoLoad">是否要自动加载</param>
        /// <param name="itemData"></param>
        /// <param name="loadStatus"></param>
        /// <returns></returns>
        protected bool TryGetCacheItem <TValue>(object[] keys, bool isAutoLoad, out TValue itemData)
        {
            CheckLoad();
            itemData = default;

            string groupKey = EntityKeyInfo.CreateKeyCode(keys);

            if (string.IsNullOrEmpty(groupKey))
            {
                return(false);
            }
            //处理分组方法加载,在内存中存在且加载不出错时,才不需要重读
            if (Collection.TryGetValue(groupKey, out object itemSet))
            {
                itemData = (TValue)itemSet;
                return(true);
            }
            if (isAutoLoad && LoadItemFactory(keys, false))
            {
                if (Collection.TryGetValue(groupKey, out itemSet))
                {
                    itemData = (TValue)itemSet;
                    return(true);
                }
            }
            return(false);
        }