/*
 * Copyright 2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.gradle.api.internal.cache;

import org.gradle.api.internal.Factory;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CacheAccessSerializer<K, V> implements Cache<K, V> {
    
    final private Lock lock = new ReentrantLock();
    final private Cache<K, V> cache;
    
    public CacheAccessSerializer(Cache<K, V> cache) {
        this.cache = cache;
    }

    public <T extends K> V get(T key, Factory<? extends V> factory) {
        lock.lock();
        try {
            return cache.get(key, factory);
        } finally {
            lock.unlock();
        }
    }

}
@@ -693,96 +693,51 @@
 ry;%0A
-%0A
 import 
-java.util.concurrent.locks.Lock;%0Aimport java.util.concurrent.locks.ReentrantLock
+org.gradle.api.internal.Synchronizer
 ;%0A%0Ap
@@ -828,37 +828,52 @@
 ate 
-Lock lock = new ReentrantLock
+Synchronizer synchronizer = new Synchronizer
 ();%0A
@@ -1038,14 +1038,26 @@
 get(
-T key,
+final T key, final
  Fac
@@ -1097,35 +1097,95 @@
     
-lock.lock();%0A        try %7B%0A
+return synchronizer.synchronize(new Factory%3CV%3E() %7B%0A            public V create() %7B%0A    
     
@@ -1236,56 +1236,25 @@
     
-%7D finally %7B%0A            lock.unlock();%0A        %7D
+    %7D%0A        %7D);
 %0A   

Use Synchronizer to serialise access to the cache