Example #1
0
        public T BlitzGet<T>(string cacheKey, Func<T> function, long? milliseconds = null)
        {
            if (memoryCache.TryGetValue(cacheKey, out T result)) return result;
            lock (LockDictionary.Get(cacheKey))
            {
                if (memoryCache.TryGetValue(cacheKey, out result)) return result;

                result = function.Invoke();
                memoryCache.Set(cacheKey, result, DateTime.Now.AddMilliseconds(milliseconds ?? defaultMilliseconds));
            }

            return result;
        }
Example #2
0
        public void LockDictionaryPerformance()
        {
            var start = DateTime.Now;

            Parallel.For(0, numberOfTests, (i) =>
            {
                LockDictionary.Get(Guid.NewGuid().ToString());
            });

            var elapsed = (DateTime.Now - start).TotalMilliseconds;


            Assert.AreEqual(numberOfTests, LockDictionary.GetNumberOfLocks());
        }
Example #3
0
 public void Remove(string cacheKey)
 {
     lock (LockDictionary.Get(cacheKey))
         memoryCache.Remove(cacheKey);
 }
Example #4
0
 public void BlitzUpdate<T>(string cacheKey, Func<T> function, long milliseconds)
 {
     lock (LockDictionary.Get(cacheKey))
         memoryCache.Set(cacheKey, function(), DateTime.Now.AddMilliseconds(milliseconds));
 }