예제 #1
0
        public object this[RequestContext context]
        {
            get
            {
                string fullSqlId = context.FullSqlId;

                if (!MappedStatements.ContainsKey(fullSqlId))
                {
                    throw new ArgumentException(string.Format("CacheManager can not find Statement.Id:{0}", fullSqlId));
                }
                var statement = MappedStatements[fullSqlId];
                if (statement.Cache == null)
                {
                    return(null);
                }
                if (statement.Cache.FlushInterval != null)
                {
                    lock (this)
                    {
                        FlushByInterval(statement);
                    }
                }
                var    cacheKey = new CacheKey(context);
                object cache    = null;
                if (statement.CacheProvider != null)
                {
                    cache = statement.CacheProvider[cacheKey];
                }
                context.Database.Debug(string.Format("CacheManager GetCache FullSqlId:{0},Success:{1} !", fullSqlId, cache != null));
                return(cache);
            }
            set
            {
                string fullSqlId = context.FullSqlId;
                if (!MappedStatements.ContainsKey(fullSqlId))
                {
                    throw new ArgumentException(string.Format("CacheManager can not find Statement.Id:{fullSqlId}"));
                }
                var statement = MappedStatements[fullSqlId];
                if (statement.Cache == null)
                {
                    return;
                }
                if (statement.Cache.FlushInterval != null)
                {
                    lock (this)
                    {
                        FlushByInterval(statement);
                    }
                }
                var cacheKey = new CacheKey(context);
                if (statement.CacheProvider != null)
                {
                    statement.CacheProvider[cacheKey] = value;
                }
                context.Database.Debug(string.Format("CacheManager SetCache FullSqlId:{0}", fullSqlId));
            }
        }
예제 #2
0
        /// <summary>
        /// Maps the statements.
        /// </summary>
        /// <param name="platform">The platform.</param>
        public void MapStatements(string platform)
        {
            MappedStatements.SetPlatform(platform);
            Settings.Platform           = platform;
            canSetExternalMapStatements = true;

            foreach (var statement in unprocessedStatements)
            {
                MappedStatements.Add(statement);
            }

            unprocessedStatements.Clear();
        }
예제 #3
0
        public object this[RequestContext context, Type type]
        {
            get
            {
                string fullSqlId = context.FullSqlId;

                if (!MappedStatements.ContainsKey(fullSqlId))
                {
                    throw new SmartSqlException($"CacheManager can not find Statement.Id:{fullSqlId}");
                }
                var statement = MappedStatements[fullSqlId];
                if (statement.Cache == null)
                {
                    return(null);
                }
                if (statement.Cache.FlushInterval != null)
                {
                    lock (this)
                    {
                        FlushByInterval(statement);
                    }
                }
                var cacheKey = new CacheKey(context);
                var cache    = statement.CacheProvider[cacheKey, type];
                _logger.LogDebug($"CacheManager GetCache FullSqlId:{fullSqlId},Success:{cache != null} !");
                return(cache);
            }
            set
            {
                string fullSqlId = context.FullSqlId;
                if (!MappedStatements.ContainsKey(fullSqlId))
                {
                    throw new SmartSqlException($"CacheManager can not find Statement.Id:{fullSqlId}");
                }
                var statement = MappedStatements[fullSqlId];
                if (statement.Cache == null)
                {
                    return;
                }
                if (statement.Cache.FlushInterval != null)
                {
                    lock (this)
                    {
                        FlushByInterval(statement);
                    }
                }
                var cacheKey = new CacheKey(context);
                statement.CacheProvider[cacheKey, type] = value;
                _logger.LogDebug($"CacheManager SetCache FullSqlId:{fullSqlId}");
            }
        }
예제 #4
0
        /// <summary>
        /// Loads the mapped statements.
        /// </summary>
        /// <param name="statements">The statements.</param>
        /// <exception cref="System.ArgumentNullException">statements</exception>
        /// <exception cref="System.InvalidOperationException">MapConfig not initialized properly. No Platform has been defined. Cannot load statements.</exception>
        public void LoadMappedStatements(IEnumerable <StatementMap> statements)
        {
            if (statements == null)
            {
                throw new ArgumentNullException("statements");
            }

            if (!canSetExternalMapStatements)
            {
                throw new InvalidOperationException(
                          "MapConfig not initialized properly. No Platform has been defined. Cannot load statements.");
            }

            foreach (var statementMap in statements)
            {
                MappedStatements.Add(statementMap);
            }
        }
예제 #5
0
 public object this[RequestContext context, Type type]
 {
     get
     {
         string fullSqlId = context.FullSqlId;
         if (!MappedStatements.ContainsKey(fullSqlId))
         {
             throw new BaraException($"CacheManager can't Load Statement which FullSqlId is {fullSqlId},Please Check!");
         }
         var statement = MappedStatements[fullSqlId];
         if (statement.Cache == null)
         {
             return(null);
         }
         lock (syncobj)
         {
             FlushByInterval(statement);
         }
         var cacheKey = new CacheKey(context);
         var cache    = statement.CacheProvider[cacheKey, type];
         _logger.LogDebug($"CacheManager GetCache From FullSqlId ${fullSqlId},Success:{cache != null}");
         return(cache);
     }
     set
     {
         string fullSqlId = context.FullSqlId;
         if (!MappedStatements.ContainsKey(fullSqlId))
         {
             throw new BaraException($"CacheManager can't Load Statement which FullSqlId is {fullSqlId},Please Check!");
         }
         var statement = MappedStatements[fullSqlId];
         if (statement.Cache == null)
         {
             return;
         }
         lock (syncobj)
         {
             FlushByInterval(statement);
         }
         var cacheKey = new CacheKey(context);
         _logger.LogDebug($"CacheManager SetCache FullSqlId:{fullSqlId}");
         statement.CacheProvider[cacheKey, type] = value;
     }
 }