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 flushed.
30 * To support clustering and high availability as well as general good cache management, caches should
31 * allow the cache manager to flush them when required by the underlying application.
32 *
33 * @return true if this cache can be flushed.
34 */
35 boolean isFlushable();
36
37 /**
38 * @return the current hint regarding the maximum number of entries that should be cached at any time.
39 * <tt>null</tt> indicates no current hint
40 */
41 Integer currentMaxEntries();
42
43 /**
44 * Attempts to update the hint regarding the maximum number of entries that should be cached at any time.
45 * @param newValue the new hint value
46 * @return <tt>true</tt> iff the hint has been updated to the new value. If a cache does not support changes at
47 * run-time, it must return <tt>false</tt>
48 */
49 boolean updateMaxEntries(int newValue);
50
51 /**
52 * @return the current hint regarding how long entries should be held in the cache, after last access, measured in milliseconds.
53 * <tt>null</tt> indicates no current hint
54 */
55 Long currentExpireAfterAccessMillis();
56
57 /**
58 * Attempts to update the hint regarding how long entries that should be held in the cache, after last access.
59 * @param expireAfter Time to retain entries for since their last access.
60 * @param timeUnit The {@link TimeUnit} for the time
61 * @return <tt>true</tt> iff the hint has been updated to the new value. If a cache does not support changes at
62 * run-time, it must return <tt>false</tt>
63 */
64 boolean updateExpireAfterAccess(long expireAfter, TimeUnit timeUnit);
65
66 /**
67 * @return the current hint regarding how long entries should be held in the cache, after last write, measured in milliseconds.
68 * <tt>null</tt> indicates no current hint
69 */
70 Long currentExpireAfterWriteMillis();
71
72 /**
73 * Attempts to update the hint regarding how long entries that should be held in the cache, after last write.
74 * @param expireAfter Time to retain entries for since their last write.
75 * @param timeUnit The {@link TimeUnit} for the time
76 * @return <tt>true</tt> iff the hint has been updated to the new value. If a cache does not support changes at
77 * run-time, it must return <tt>false</tt>
78 */
79 boolean updateExpireAfterWrite(long expireAfter, TimeUnit timeUnit);
80
81 /**
82 * @return true if the cache is local, and hence is not replicated in a clustered environment
83 */
84 boolean isLocal();
85
86 /**
87 * @return true if this cache should be replicated asynchronously in a clustered environment.
88 */
89 boolean isReplicateAsynchronously();
90
91 /**
92 * @return true if this cache should, in a clustered environment, replicate put and update operations
93 * by copying the relevant key and value across the wire (as opposed to just the key).
94 */
95 boolean isReplicateViaCopy();
96 }