Cache domains, contacts, and hosts in WHOIS queries

This should prevent having issues with hot key paths on entities that
experience a heavy WHOIS volume (e.g. contacts that registrars reuse on
many domains).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191506124
This commit is contained in:
mcilwain 2018-04-03 15:05:00 -07:00 committed by Ben McIlwain
parent cfd83ad4dc
commit 07d38340f3
9 changed files with 184 additions and 34 deletions

View file

@ -22,6 +22,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.TypeUtils.instantiate;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
@ -218,13 +219,18 @@ public abstract class ForeignKeyIndex<E extends EppResource> extends BackupGroup
* given IDs (blah) don't exist."
*/
@NonFinalForTesting
static LoadingCache<Key<ForeignKeyIndex<?>>, Optional<ForeignKeyIndex<?>>>
private static LoadingCache<Key<ForeignKeyIndex<?>>, Optional<ForeignKeyIndex<?>>>
cacheForeignKeyIndexes =
CacheBuilder.newBuilder()
.expireAfterWrite(getEppResourceCachingDuration().getMillis(), MILLISECONDS)
.maximumSize(getEppResourceMaxCachedEntries())
.build(CACHE_LOADER);
@VisibleForTesting
public static void setCacheForTest(CacheBuilder<Object, Object> cacheBuilder) {
cacheForeignKeyIndexes = cacheBuilder.build(CACHE_LOADER);
}
/**
* Load a list of {@link ForeignKeyIndex} instances by class and id strings that are active at or
* after the specified moment in time, using the cache if enabled.