View Javadoc

1   package com.atlassian.vcache;
2   
3   import java.util.Arrays;
4   import java.util.Map;
5   import java.util.Optional;
6   import java.util.concurrent.CompletableFuture;
7   import javax.annotation.Nonnull;
8   
9   import com.atlassian.annotations.PublicApi;
10  
11  /**
12   * Represents an {@link ExternalCache} where all operations are performed directly on the external cache system.
13   * See the {@link ExternalCache} documentation for more information.
14   *
15   * @param <V> the value type
16   *
17   * @since 1.0
18   */
19  @PublicApi
20  public interface DirectExternalCache<V>
21          extends ExternalCache<V>, ExternalWriteOperationsUnbuffered<V>
22  {
23      /**
24       * Returns an identified value that is associated with a specified key. The {@link IdentifiedValue#identifier()}
25       * may be used in subsequent CAS operations, such as
26       * {@link #removeIf(String, CasIdentifier)} and
27       * {@link #replaceIf(String, CasIdentifier, Object)}.
28       *
29       * @param key the key to check.
30       * @return an {@link Optional} which may contain the identified value associated with the key.
31       */
32      @Nonnull
33      CompletableFuture<Optional<IdentifiedValue<V>>> getIdentified(String key);
34  
35      @SuppressWarnings("unchecked")
36      @Nonnull
37      default CompletableFuture<Map<String, Optional<IdentifiedValue<V>>>> getBulkIdentified(String... keys)
38      {
39          return getBulkIdentified(Arrays.asList(keys));
40      }
41  
42      @Nonnull
43      CompletableFuture<Map<String, Optional<IdentifiedValue<V>>>> getBulkIdentified(Iterable<String> keys);
44  
45      /**
46       * Removes the specified entry, iff the specified CAS identifier matches.
47       *
48       * @param key the key of the entry to remove
49       * @param casId the CAS identifier to match
50       * @return whether the entry was removed
51       */
52      @Nonnull
53      CompletableFuture<Boolean> removeIf(String key, CasIdentifier casId);
54  
55      /**
56       * Replaces the value for a specified entry, iff the specified CAS identifier matches.
57       *
58       * @param key the key of the entry to replace it's value
59       * @param casId the CAS identifier to match
60       * @param newValue the new value to replace with
61       * @return whether the value was replaced
62       */
63      @Nonnull
64      CompletableFuture<Boolean> replaceIf(String key, CasIdentifier casId, V newValue);
65  }