View Javadoc
1   package com.atlassian.cache;
2   
3   import javax.annotation.Nonnull;
4   import javax.annotation.Nullable;
5   
6   import com.atlassian.annotations.PublicApi;
7   
8   /**
9    * An immutable representation of settings for a Cache. The property getters will return
10   * <tt>null</tt> to indicate that no setting is specified. The caller is
11   * responsible for handling that <tt>null</tt> may be returned.
12   * @since 2.0
13   */
14  @PublicApi
15  public interface CacheSettings
16  {
17      /**
18       * @return how long to retain entries (in milliseconds) from when they were last accessed, or <tt>null</tt>.
19       */
20      @Nullable
21      Long getExpireAfterAccess();
22  
23      /**
24       * Convenience method that returns {@link #getExpireAfterAccess()} if it is not <tt>null</tt>,
25       * otherwise returns the supplied <tt>defaultValue</tt>.
26       */
27      long getExpireAfterAccess(long defaultValue);
28  
29      /**
30       * @return how long to retain entries (in milliseconds) from when they were created, or <tt>null</tt>.
31       */
32      @Nullable
33      Long getExpireAfterWrite();
34  
35      /**
36       * Convenience method that returns {@link #getExpireAfterWrite()} if it is not <tt>null</tt>,
37       * otherwise returns the supplied <tt>defaultValue</tt>.
38       */
39      long getExpireAfterWrite(long defaultValue);
40  
41      /**
42       * @return whether this cache can be flushed by the cache manager when desired, or <tt>null</tt>.
43       */
44      @Nullable
45      Boolean getFlushable();
46  
47      /**
48       * Convenience method that returns {@link #getFlushable()} if it is not <tt>null</tt>,
49       * otherwise returns the supplied <tt>defaultValue</tt>.
50       */
51      boolean getFlushable(boolean defaultValue);
52  
53      /**
54       * @return whether this cache should be local to the node (jvm) where the cache is created, or <tt>null</tt>.
55       */
56      @Nullable
57      Boolean getLocal();
58  
59      /**
60       * Convenience method that returns {@link #getLocal()} if it is not <tt>null</tt>,
61       * otherwise returns the supplied <tt>defaultValue</tt>.
62       */
63      boolean getLocal(boolean defaultValue);
64  
65      /**
66       * @return the maximum number of entries in the cache, or <tt>null</tt>.
67       */
68      @Nullable
69      Integer getMaxEntries();
70  
71      /**
72       * Convenience method that returns {@link #getMaxEntries()} if it is not <tt>null</tt>,
73       * otherwise returns the supplied <tt>defaultValue</tt>.
74       */
75      int getMaxEntries(int defaultValue);
76  
77      /**
78       * @return whether this cache should replicate asynchronously, or <tt>null</tt>.
79       */
80      @Nullable
81      Boolean getReplicateAsynchronously();
82  
83      /**
84       * Convenience method that returns {@link #getReplicateAsynchronously()} if it is not <tt>null</tt>,
85       * otherwise returns the supplied <tt>defaultValue</tt>.
86       */
87      boolean getReplicateAsynchronously(boolean defaultValue);
88  
89      /**
90       * @return whether this cache should replicate put and update operations by copying the relevant
91       * key and value across the wire, or <tt>null</tt>.
92       */
93      @Nullable
94      Boolean getReplicateViaCopy();
95  
96      /**
97       * Convenience method that returns {@link #getReplicateViaCopy()} if it is not <tt>null</tt>,
98       * otherwise returns the supplied <tt>defaultValue</tt>.
99       */
100     boolean getReplicateViaCopy(boolean defaultValue);
101 
102     /**
103      * @return whether this cache should record statistics or not, or <tt>null</tt>.
104      */
105     @Nullable
106     Boolean getStatisticsEnabled();
107 
108     /**
109      * Convenience method that returns {@link #getStatisticsEnabled()} ()} if it is not <tt>null</tt>,
110      * otherwise returns the supplied <tt>defaultValue</tt>.
111      */
112     boolean getStatisticsEnabled(boolean defaultValue);
113 
114     /**
115      * Returns a new {@link CacheSettings} instance where the current settings
116      * are overridden with settings specified in <tt>overrides</tt>. Only properties
117      * in <tt>overrides</tt> that are not <tt>null</tt> will be applied.
118      * @param overrides contains the settings to override
119      * @return a new {@link CacheSettings} instance with the <tt>overrides</tt> settings applied.
120      */
121     @Nonnull
122     CacheSettings override(@Nonnull CacheSettings overrides);
123 }