View Javadoc

1   package com.atlassian.vcache;
2   
3   import java.time.Duration;
4   import java.util.Optional;
5   import javax.annotation.Nonnull;
6   
7   import com.atlassian.annotations.PublicApi;
8   
9   import static java.util.Objects.requireNonNull;
10  
11  /**
12   * An immutable representation of settings for an {@link JvmCache}.
13   *
14   * @since 1.0
15   */
16  @PublicApi
17  public class JvmCacheSettings
18  {
19      private final Optional<Integer> maxEntries;
20      private final Optional<Duration> defaultTtl;
21  
22      JvmCacheSettings(Optional<Integer> maxEntries, Optional<Duration> defaultTtl)
23      {
24          this.maxEntries = requireNonNull(maxEntries);
25          this.defaultTtl = requireNonNull(defaultTtl);
26      }
27  
28      /**
29       * Returns a new {@link JvmCacheSettings} instance where the current settings
30       * are overridden with settings specified in <tt>overrides</tt>. Only properties
31       * in <tt>overrides</tt> that are present will be applied.
32       * @param overrides contains the settings to override
33       * @return a new {@link JvmCacheSettings} instance with the <tt>overrides</tt> settings applied.
34       */
35      @Nonnull
36      public JvmCacheSettings override(JvmCacheSettings overrides)
37      {
38          //TODO: implement
39          return overrides;
40      }
41  
42      /**
43       * Returns the maximum number of entries allowed.
44       * @return the maximum number of entries allowed.
45       */
46      @Nonnull
47      public Optional<Integer> getMaxEntries()
48      {
49          return maxEntries;
50      }
51  
52      /**
53       * Returns the default time-to-live for entries when added.
54       * @return the default time-to-live for entries when added.
55       */
56      @Nonnull
57      public Optional<Duration> getDefaultTtl()
58      {
59          return defaultTtl;
60      }
61  }