From 73f11bd45ad5901e1fe209e725d3988906019a30 Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 10 Aug 2012 12:16:27 -0700 Subject: [PATCH] [FileBackend] Refactored Swift backend to use ProcessCacheLRU. Change-Id: I1d74c751a98584ca8b1c9ca4bc58d64d521fb679 --- includes/filebackend/SwiftFileBackend.php | 40 ++++++++++------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php index 5be86e6807..ea66bf65fb 100644 --- a/includes/filebackend/SwiftFileBackend.php +++ b/includes/filebackend/SwiftFileBackend.php @@ -45,14 +45,14 @@ class SwiftFileBackend extends FileBackendStore { protected $swiftCDNExpiry; // integer; how long to cache things in the CDN protected $swiftCDNPurgable; // boolean; whether object CDN purging is enabled - protected $maxContCacheSize = 300; // integer; max containers with entries - /** @var CF_Connection */ protected $conn; // Swift connection handle protected $connStarted = 0; // integer UNIX timestamp - protected $connContainers = array(); // container object cache protected $connException; // CloudFiles exception + /** @var ProcessCacheLRU */ + protected $connContainerCache; // container object cache + /** * @see FileBackendStore::__construct() * Additional $config params include: @@ -109,6 +109,8 @@ class SwiftFileBackend extends FileBackendStore { : true; // Cache container info to mask latency $this->memCache = wfGetMainCache(); + // Process cache for container info + $this->connContainerCache = new ProcessCacheLRU( 300 ); } /** @@ -1135,7 +1137,7 @@ class SwiftFileBackend extends FileBackendStore { // Authenticate with proxy and get a session key... if ( !$this->conn ) { $this->connStarted = 0; - $this->connContainers = array(); + $this->connContainerCache->clear(); try { $this->auth->authenticate(); $this->conn = new CF_Connection( $this->auth ); @@ -1152,7 +1154,7 @@ class SwiftFileBackend extends FileBackendStore { * @see FileBackendStore::doClearCache() */ protected function doClearCache( array $paths = null ) { - $this->connContainers = array(); // clear container object cache + $this->connContainerCache->clear(); // clear container object cache } /** @@ -1167,25 +1169,21 @@ class SwiftFileBackend extends FileBackendStore { protected function getContainer( $container, $bypassCache = false ) { $conn = $this->getConnection(); // Swift proxy connection if ( $bypassCache ) { // purge cache - unset( $this->connContainers[$container] ); - } elseif ( !isset( $this->connContainers[$container] ) ) { + $this->connContainerCache->clear( $container ); + } elseif ( !$this->connContainerCache->has( $container, 'obj' ) ) { $this->primeContainerCache( array( $container ) ); // check persistent cache } - if ( !isset( $this->connContainers[$container] ) ) { + if ( !$this->connContainerCache->has( $container, 'obj' ) ) { $contObj = $conn->get_container( $container ); // NoSuchContainerException not thrown: container must exist - if ( count( $this->connContainers ) >= $this->maxContCacheSize ) { // trim cache? - reset( $this->connContainers ); - unset( $this->connContainers[key( $this->connContainers )] ); - } - $this->connContainers[$container] = $contObj; // cache it + $this->connContainerCache->set( $container, 'obj', $contObj ); // cache it if ( !$bypassCache ) { $this->setContainerCache( $container, // update persistent cache array( 'bytes' => $contObj->bytes_used, 'count' => $contObj->object_count ) ); } } - return $this->connContainers[$container]; + return $this->connContainerCache->get( $container, 'obj' ); } /** @@ -1198,7 +1196,7 @@ class SwiftFileBackend extends FileBackendStore { protected function createContainer( $container ) { $conn = $this->getConnection(); // Swift proxy connection $contObj = $conn->create_container( $container ); - $this->connContainers[$container] = $contObj; // cache it + $this->connContainerCache->set( $container, 'obj', $contObj ); // cache return $contObj; } @@ -1211,7 +1209,7 @@ class SwiftFileBackend extends FileBackendStore { */ protected function deleteContainer( $container ) { $conn = $this->getConnection(); // Swift proxy connection - unset( $this->connContainers[$container] ); // purge cache + $this->connContainerCache->clear( $container ); // purge $conn->delete_container( $container ); } @@ -1223,13 +1221,9 @@ class SwiftFileBackend extends FileBackendStore { try { $conn = $this->getConnection(); // Swift proxy connection foreach ( $containerInfo as $container => $info ) { - $this->connContainers[$container] = new CF_Container( - $conn->cfs_auth, - $conn->cfs_http, - $container, - $info['count'], - $info['bytes'] - ); + $contObj = new CF_Container( $conn->cfs_auth, $conn->cfs_http, + $container, $info['count'], $info['bytes'] ); + $this->connContainerCache->set( $container, 'obj', $contObj ); } } catch ( CloudFilesException $e ) { // some other exception? $this->handleException( $e, null, __METHOD__, array() ); -- 2.20.1