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 ExternalCache}.
13   *
14   * @since 1.0
15   */
16  @PublicApi
17  public class ExternalCacheSettings
18  {
19      private final Optional<Duration> defaultTtl;
20      private final Optional<Integer> entryCountHint;
21      private final Optional<ChangeRate> dataChangeRateHint;
22      private final Optional<ChangeRate> entryGrowthRateHint;
23  
24      ExternalCacheSettings(
25              Optional<Duration> defaultTtl,
26              Optional<Integer> entryCountHint,
27              Optional<ChangeRate> dataChangeRateHint,
28              Optional<ChangeRate> entryGrowthRateHint)
29      {
30          this.defaultTtl = requireNonNull(defaultTtl);
31          this.entryCountHint = requireNonNull(entryCountHint);
32          this.dataChangeRateHint = requireNonNull(dataChangeRateHint);
33          this.entryGrowthRateHint = requireNonNull(entryGrowthRateHint);
34      }
35  
36      /**
37       * Returns a new {@link ExternalCacheSettings} instance where the current settings
38       * are overridden with settings specified in <tt>overrides</tt>.
39       * @param overrides contains the settings to override
40       * @return a new {@link ExternalCacheSettings} instance with the <tt>overrides</tt> settings applied.
41       */
42      @Nonnull
43      public ExternalCacheSettings override(ExternalCacheSettings overrides)
44      {
45          //TODO: implement
46          return overrides;
47      }
48  
49      /**
50       * Returns the default time-to-live for entries when added.
51       * @return the default time-to-live for entries when added.
52       */
53      @Nonnull
54      public Optional<Duration> getDefaultTtl()
55      {
56          return defaultTtl;
57      }
58  
59      /**
60       * Returns the hint for the expected number of entries
61       * @return the hint for the expected number of entries
62       */
63      @Nonnull
64      public Optional<Integer> getEntryCountHint()
65      {
66          return entryCountHint;
67      }
68  
69      /**
70       * Returns the hint for the expected change rate for data updates.
71       * @return the hint for the expected change rate for data updates.
72       */
73      @Nonnull
74      public Optional<ChangeRate> getDataChangeRateHint()
75      {
76          return dataChangeRateHint;
77      }
78  
79      /**
80       * Returns the hint for the expected change rate for entry additions.
81       * @return the hint for the expected change rate for entry additions.
82       */
83      @Nonnull
84      public Optional<ChangeRate> getEntryGrowthRateHint()
85      {
86          return entryGrowthRateHint;
87      }
88  }