public void TestLockSemaphoreSlim()
        {
            var lockStore = new SemaphoreSlimLockStore();
            var o1        = lockStore.GetLockObject("MyString");
            var o2        = lockStore.GetLockObject("MyString2");

            Assert.AreNotEqual(o1, o2, "Should not have same lock object");
            var o1_2 = lockStore.GetLockObject("MyString");

            Assert.AreEqual(o1, o1_2, "Should have same lock object");
        }
Exemple #2
0
        public void Replace <T>(string cacheKey, Func <T, T> replaceAlg, TimeSpan?cacheTime = null)
        {
            cacheKey = StandardizeCacheKey(cacheKey);

            var sema = _semaphoreSlimLockStore.GetLockObject(cacheKey);

            sema.Wait();
            try
            {
                SetItem(cacheKey, replaceAlg(Retrieve <T>(cacheKey)), cacheTime);
            }
            finally
            {
                sema.Release();
            }

            //lock (_lockStore.GetLockObject(cacheKey))
            //{
            //    SetItem(cacheKey, replaceAlg(Retrieve<T>(cacheKey)), cacheTime);
            //}
        }