View Javadoc

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