From 05b443fe4d151b971ac671120f95219648ca3456 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 12 Mar 2013 17:22:00 -0700 Subject: [PATCH] Memoize Swift TempURL keys This avoids a round-trip to the server for every signed URL. --- .../config/TemporaryUrlExtensionModule.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/TemporaryUrlExtensionModule.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/TemporaryUrlExtensionModule.java index 71bcd40c20..81e3e3f0f7 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/TemporaryUrlExtensionModule.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/config/TemporaryUrlExtensionModule.java @@ -19,6 +19,10 @@ package org.jclouds.openstack.swift.blobstore.config; import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient; +import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; + +import java.util.concurrent.TimeUnit; +import javax.inject.Singleton; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.date.TimeStamp; @@ -33,7 +37,10 @@ import org.jclouds.openstack.swift.extensions.TemporaryUrlKeyAsyncApi; import org.jclouds.openstack.swift.suppliers.ReturnOrFetchTemporaryUrlKey; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.name.Named; import com.google.inject.Provides; import com.google.inject.TypeLiteral; @@ -85,7 +92,24 @@ public abstract class TemporaryUrlExtensionModule>() { - }).annotatedWith(TemporaryUrlKey.class).to(ReturnOrFetchTemporaryUrlKey.class); + }).annotatedWith(TemporaryUrlKey.class).to(ReturnOrFetchTemporaryUrlKeyMemoized.class); + } + + @Singleton + private static class ReturnOrFetchTemporaryUrlKeyMemoized implements Supplier { + private final Supplier delegate; + + @Inject + private ReturnOrFetchTemporaryUrlKeyMemoized(TemporaryUrlKeyApi client, + @Named(PROPERTY_SESSION_INTERVAL) long sessionInterval) { + this.delegate = Suppliers.memoizeWithExpiration( + new ReturnOrFetchTemporaryUrlKey(client), sessionInterval, TimeUnit.SECONDS); + } + + @Override + public String get() { + return delegate.get(); + } } protected abstract void bindRequestSigner(); @@ -94,4 +118,4 @@ public abstract class TemporaryUrlExtensionModule