Example #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));
            }
        }
Example #2
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}");
            }
        }
Example #3
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;
     }
 }