private void Increment(PerformanceLogger logger)
        {
            if (_persistence != null) {
                if (_persistence != null) {
                    Dictionary<string, Counter> counters;
                    if (_persistence.Contains("request-counters")) {
                        counters = _persistence["request-counters"] as Dictionary<string, Counter>;
                    } else {
                        counters = new Dictionary<string, Counter>();
                        _persistence["request-counters"] = counters;
                    }

                    if (counters.ContainsKey(logger._name)) {
                        counters[logger._name].Add(logger);
                    } else {
                        counters[logger._name] = new Counter() {
                            TotalMilliseconds = logger._time,
                            Count = 1,
                            Stack = Environment.StackTrace
                        };
                    }
                }

            }
        }
示例#2
0
        public void GetMany(List <GetReference> req)
        {
            if (_cache == null)
            {
                return;
            }

            using (var log = new PerformanceLogger("redis-get-many", _loggingPersistence)) {
                for (var i = 0; i < req.Count; i++)
                {
                    var r = req[i];
                    if (r.ExpectSingleValue)
                    {
                        var val = _cache.Get(r.CacheKey) as ITableBacked;

                        if (val == null)
                        {
                            req[i].Result = null;
                        }
                        else
                        {
                            req[i].Result = new ITableBacked[] { val }.ToList();
                        }
                    }
                    else
                    {
                        req[i].Result = _cache.Get(r.CacheKey) as List <ITableBacked>;
                    }
                }
            }
            return;
        }
示例#3
0
        private void Increment(PerformanceLogger logger)
        {
            if (_persistence != null)
            {
                if (_persistence != null)
                {
                    Dictionary <string, Counter> counters;
                    if (_persistence.Contains("request-counters"))
                    {
                        counters = _persistence["request-counters"] as Dictionary <string, Counter>;
                    }
                    else
                    {
                        counters = new Dictionary <string, Counter>();
                        _persistence["request-counters"] = counters;
                    }

                    if (counters.ContainsKey(logger._name))
                    {
                        counters[logger._name].Add(logger);
                    }
                    else
                    {
                        counters[logger._name] = new Counter()
                        {
                            TotalMilliseconds = logger._time,
                            Count             = 1,
                            Stack             = Environment.StackTrace
                        };
                    }
                }
            }
        }
示例#4
0
        public void GetMany(List <GetReference> req)
        {
            if (_db == null)
            {
                return;
            }

            using (var log = new PerformanceLogger("redis-get-many", _loggingPersistence)) {
                var values = _db.StringGet(
                    req.Select(x => (RedisKey)x.CacheKey)
                    .ToArray()
                    );

                for (var i = 0; i < values.Length; i++)
                {
                    if (req[i].ExpectSingleValue)
                    {
                        var val = DeserializeSingle(values[i]);
                        if (val == null)
                        {
                            req[i].Result = null;
                        }
                        else
                        {
                            req[i].Result = new ITableBacked[] { val }.ToList();
                        }
                    }
                    else
                    {
                        req[i].Result = DeserializeList(values[i]);
                    }
                }
            }
            return;
        }
示例#5
0
            public void Add(PerformanceLogger log)
            {
                Count++;
                TotalMilliseconds += log._time;


                Stack = Environment.StackTrace;
            }
示例#6
0
 public bool Set <T>(string cacheKey, T value) where T : class
 {
     if (_cache == null)
     {
         return(false);
     }
     using (var log = new PerformanceLogger("redis-set", _loggingPersistence)) {
         using (var log2 = new PerformanceLogger("redis-set|" + cacheKey, _loggingPersistence)) {
             _cache.Set(cacheKey, value, new CacheItemPolicy());
             return(true);
         }
     }
 }
示例#7
0
        public T Get <T>(string cacheKey) where T : class
        {
            if (_cache == null)
            {
                return(null);
            }


            using (var log = new PerformanceLogger("redis-get", _loggingPersistence)) {
                using (var log2 = new PerformanceLogger("redis-get|" + cacheKey, _loggingPersistence)) {
                    return(_cache.Get(cacheKey) as T);
                }
            }
        }
示例#8
0
 public bool Set <T>(string cacheKey, T value) where T : class
 {
     if (_db == null)
     {
         return(false);
     }
     using (var log = new PerformanceLogger("redis-set", _loggingPersistence)) {
         using (var log2 = new PerformanceLogger("redis-set|" + cacheKey, _loggingPersistence)) {
             byte[] buffer = Serialize(value);
             _db.StringSet(cacheKey, buffer);
             return(true);
         }
     }
 }
示例#9
0
        public T Get <T>(string cacheKey) where T : class
        {
            if (_db == null)
            {
                return(null);
            }


            using (var log = new PerformanceLogger("redis-get", _loggingPersistence)) {
                using (var log2 = new PerformanceLogger("redis-get|" + cacheKey, _loggingPersistence)) {
                    byte[] buffer = _db.StringGet(cacheKey);
                    return(Deserialize <T>(buffer));
                }
            }
        }
示例#10
0
        public async Task <List <T> > GetManyAsync <T>(List <string> cacheKeys) where T : class
        {
            if (_db == null)
            {
                return(null);
            }
            using (var log = new PerformanceLogger("redis-get-many", _loggingPersistence)) {
                var values = await _db.StringGetAsync(
                    cacheKeys
                    .Select(x => (RedisKey)x)
                    .ToArray()
                    );

                return(values.Select(x => Deserialize <T>(x)).ToList());
            }
        }
示例#11
0
            public void Add(PerformanceLogger log)
            {
                Count++;
                TotalMilliseconds += log._time;

                Stack = Environment.StackTrace;
            }