1 package com.atlassian.cache;
2
3 import java.util.concurrent.TimeUnit;
4
5 import com.atlassian.annotations.Internal;
6
7 /**
8 * Interface that managed cache things need to implement
9 *
10 *
11 * @since 2.0
12 */
13 @Internal
14 public interface ManagedCache
15 {
16 /**
17 * Clear the cache.
18 */
19 void clear();
20
21 /**
22 * The name of the cache, uniquely identifies this cache.
23 *
24 * @return the name of the cache.
25 */
26 String getName();
27
28 /**
29 * Returns true if this cache can be safely flushed any time.
30 * <p>
31 * This method is used by {@link CacheManager#flushCaches()} to only flush
32 * caches that can be safely flushed. {@link #clear()} ignores this value.
33 *
34 * @return true if this cache can be flushed safely.
35 */
36 boolean isFlushable();
37
38 /**
39 * @return the current hint regarding the maximum number of entries that should be cached at any time.
40 * <tt>null</tt> indicates no current hint
41 */
42 Integer currentMaxEntries();
43
44 /**
45 * Attempts to update the hint regarding the maximum number of entries that should be cached at any time.
46 * @param newValue the new hint value
47 * @return <tt>true</tt> iff the hint has been updated to the new value. If a cache does not support changes at
48 * run-time, it must return <tt>false</tt>
49 */
50 boolean updateMaxEntries(int newValue);
51
52 /**
53 * @return the current hint regarding how long entries should be held in the cache, after last access, measured in milliseconds.
54 * <tt>null</tt> indicates no current hint
55 */
56 Long currentExpireAfterAccessMillis();
57
58 /**
59 * Attempts to update the hint regarding how long entries that should be held in the cache, after last access.
60 * @param expireAfter Time to retain entries for since their last access.
61 * @param timeUnit The {@link TimeUnit} for the time
62 * @return <tt>true</tt> iff the hint has been updated to the new value. If a cache does not support changes at
63 * run-time, it must return <tt>false</tt>
64 */
65 boolean updateExpireAfterAccess(long expireAfter, TimeUnit timeUnit);
66
67 /**
68 * @return the current hint regarding how long entries should be held in the cache, after last write, measured in milliseconds.
69 * <tt>null</tt> indicates no current hint
70 */
71 Long currentExpireAfterWriteMillis();
72
73 /**
74 * Attempts to update the hint regarding how long entries that should be held in the cache, after last write.
75 * @param expireAfter Time to retain entries for since their last write.
76 * @param timeUnit The {@link TimeUnit} for the time
77 * @return <tt>true</tt> iff the hint has been updated to the new value. If a cache does not support changes at
78 * run-time, it must return <tt>false</tt>
79 */
80 boolean updateExpireAfterWrite(long expireAfter, TimeUnit timeUnit);
81
82 /**
83 * @return true if the cache is local, and hence is not replicated in a clustered environment
84 */
85 boolean isLocal();
86
87 /**
88 * @return true if this cache should be replicated asynchronously in a clustered environment.
89 */
90 boolean isReplicateAsynchronously();
91
92 /**
93 * @return true if this cache should, in a clustered environment, replicate put and update operations
94 * by copying the relevant key and value across the wire (as opposed to just the key).
95 */
96 boolean isReplicateViaCopy();
97 }