LocatableResolver { public <T> ScopedValue<T> wrap(T value) { return new ScopedValue<>(value, this); } protected  LocatableResolver(@Nonnull FDBDatabase database,
                                @Nullable KeySpacePath path,
                                @Nullable CompletableFuture<ResolvedKeySpacePath> resolvedPath); ScopedValue<T> wrap(T value); @Nonnull FDBDatabase getDatabase(); @Nonnull CompletableFuture<Long> resolve(@Nonnull String name); @Nonnull CompletableFuture<Long> resolve(@Nullable FDBStoreTimer timer, @Nonnull String name); @API(API.Status.UNSTABLE) @Nonnull CompletableFuture<Long> resolve(@Nonnull FDBRecordContext context, @Nonnull String name); @Nonnull CompletableFuture<Long> resolve(@Nonnull String name,
                                           @Nonnull ResolverCreateHooks hooks); @Nonnull CompletableFuture<Long> resolve(@Nullable FDBStoreTimer timer,
                                           @Nonnull String name,
                                           @Nonnull ResolverCreateHooks hooks); @API(API.Status.UNSTABLE) @Nonnull CompletableFuture<Long> resolve(@Nonnull FDBRecordContext context,
                                           @Nonnull String name,
                                           @Nonnull ResolverCreateHooks hooks); @Nonnull CompletableFuture<ResolverResult> resolveWithMetadata(@Nonnull String name,
                                                                 @Nonnull ResolverCreateHooks hooks); @Nonnull CompletableFuture<ResolverResult> resolveWithMetadata(@Nullable FDBStoreTimer timer,
                                                                 @Nonnull String name,
                                                                 @Nonnull ResolverCreateHooks hooks); @API(API.Status.UNSTABLE) @Nonnull CompletableFuture<ResolverResult> resolveWithMetadata(@Nonnull FDBRecordContext context, @Nonnull String name, @Nonnull ResolverCreateHooks hooks); @Nonnull CompletableFuture<ResolverResult> mustResolveWithMetadata(@Nonnull FDBRecordContext context, @Nonnull String name); CompletableFuture<Long> mustResolve(@Nonnull FDBRecordContext context, @Nonnull String name); @Nonnull CompletableFuture<String> reverseLookup(@Nullable FDBStoreTimer timer, @Nonnull Long value); @Nonnull CompletableFuture<Void> exclusiveLock(); @Nonnull CompletableFuture<Void> enableWriteLock(); @Nonnull CompletableFuture<Void> disableWriteLock(); @Nonnull CompletableFuture<Void> retireLayer(); @Nonnull CompletableFuture<Void> incrementVersion(); @Nonnull CompletableFuture<Integer> getVersion(@Nullable FDBStoreTimer timer); @Nonnull CompletableFuture<Boolean> retired(@Nullable FDBStoreTimer timer); @Nonnull CompletableFuture<Boolean> retiredSkipCache(@Nonnull FDBRecordContext context); @Nonnull CompletableFuture<Void> updateMetadataAndVersion(@Nonnull final String key,
                                                            @Nullable final byte[] metadata); @VisibleForTesting final CompletableFuture<Void> setMapping(FDBRecordContext context, String key, Long value); @VisibleForTesting abstract CompletableFuture<Void> setWindow(long count); @Nonnull @API(API.Status.DEPRECATED) @Deprecated Subspace getMappingSubspace(); @Nonnull abstract CompletableFuture<Subspace> getMappingSubspaceAsync(); @Nonnull @API(API.Status.DEPRECATED) @Deprecated Subspace getBaseSubspace(); @Nonnull abstract CompletableFuture<Subspace> getBaseSubspaceAsync(); @Nonnull abstract ResolverResult deserializeValue(byte[] value); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void testScopedCaching() { KeySpace keySpace = new KeySpace( new KeySpaceDirectory("path1", KeyType.STRING, "path1"), new KeySpaceDirectory("path2", KeyType.STRING, "path2") ); try (FDBRecordContext context = database.openContext()) { final ResolvedKeySpacePath path1 = keySpace.resolveFromKey(context, Tuple.from("path1")); final LocatableResolver resolver1 = scopedDirectoryGenerator.apply(database, path1); Cache<ScopedValue<String>, Long> cache = CacheBuilder.newBuilder().build(); cache.put(resolver1.wrap("stuff"), 1L); assertThat("values can be read from the cache by scoped string", cache.getIfPresent(resolver1.wrap("stuff")), is(1L)); assertThat("cache misses when looking for unknown name in scope", cache.getIfPresent(resolver1.wrap("missing")), equalTo(null)); final ResolvedKeySpacePath path2 = keySpace.resolveFromKey(context, Tuple.from("path2")); final LocatableResolver resolver2 = scopedDirectoryGenerator.apply(database, path2); assertThat("cache misses when string is not in this scope", cache.getIfPresent(resolver2.wrap("stuff")), equalTo(null)); final LocatableResolver newResolver = scopedDirectoryGenerator.apply(database, path1); assertThat("scoping is determined by value of scope directory, not a reference to it", cache.getIfPresent(newResolver.wrap("stuff")), is(1L)); } }