Sfoglia il codice sorgente

Add cache to the lock file reading

Jordi Boggiano 13 anni fa
parent
commit
366176fc73
1 ha cambiato i file con 9 aggiunte e 1 eliminazioni
  1. 9 1
      src/Composer/Package/Locker.php

+ 9 - 1
src/Composer/Package/Locker.php

@@ -26,6 +26,7 @@ class Locker
     private $lockFile;
     private $repositoryManager;
     private $hash;
+    private $lockDataCache;
 
     /**
      * Initializes packages locker.
@@ -108,7 +109,11 @@ class Locker
             throw new \LogicException('No lockfile found. Unable to read locked packages');
         }
 
-        return $this->lockFile->read();
+        if (null !== $this->lockDataCache) {
+            return $this->lockDataCache;
+        }
+
+        return $this->lockDataCache = $this->lockFile->read();
     }
 
     /**
@@ -150,5 +155,8 @@ class Locker
         });
 
         $this->lockFile->write($lock);
+
+        // invalidate cache
+        $this->lockDataCache = null;
     }
 }