public void Execute(ILuaSqlExecutePolicyExecutorInfo info)
        {
            string defCacheType = null;

            //query和scalar才进行缓存
            if (info.ExecuteType == ConfigSqlExecuteType.query)
            {
                defCacheType = QueryCacheExtensions.CacheType;
            }
            else if (info.ExecuteType == ConfigSqlExecuteType.scalar)
            {
                defCacheType = ScalarCacheExtensions.CacheType;
            }

            if (defCacheType != null)
            {
                //执行缓存策略
                var policy = info.GetPolicy() as SqlL2QueryCachePolicy;
                //是否配置了查询缓存
                if (IsUsePolicy(policy))
                {
                    var cacheType = string.IsNullOrEmpty(policy.Type) ? defCacheType : policy.Type;
                    var rtn       = _cache.Cache(info.TableName, cacheType,
                                                 _util.CombineSqlAndParamsToString(info.Sql, info.SqlParams),
                                                 info.ToDBExecutor, policy.Expiry, info.ReturnType);
                    info.ReturnValue = rtn;

                    //执行缓存成功,那么结束
                    info.IsEnd = true;
                }
            }
        }
Exemple #2
0
        public void Execute(ISqlExecutePolicyExecutorInfo info)
        {
            //query和scalar才进行缓存
            if (info.ExecuteType == ConfigSqlExecuteType.query || info.ExecuteType == ConfigSqlExecuteType.scalar)
            {
                //执行缓存策略
                var policy = info.GetPolicy() as SqlL1QueryCachePolicy;
                //是否配置了查询缓存
                if (IsUsePolicy(policy))
                {
                    var    key = _util.CombineSqlAndParamsToString(info.Sql, info.SqlParams);
                    object obj;
                    //查看存不存在缓存数据
                    if (!info.SqlExecutorTempDatas.TryGetValue(key, out obj))
                    {
                        //到数据库中获取
                        obj = info.ToDBExecutor();
                        //缓存
                        info.SqlExecutorTempDatas[key] = obj;
                    }

                    info.ReturnValue = obj;
                    //执行缓存成功,那么结束
                    info.IsEnd = true;
                }
            }
        }