1   package com.trendmicro.grid.acl.ds.cache;
2   
3   import java.util.Collection;
4   import java.util.Map;
5   
6   /**
7    * Defines the interface to communicate with a cache destination (used to store elements in a cache).
8    *
9    * @author juergen_kellerer, 2011-03-25
10   * @version 1.0
11   */
12  public interface CacheDestination<K, V> {
13  
14  	/**
15  	 * Defines the mode of operation for cache writes.
16  	 */
17  	enum Mode {
18  		/**
19  		 * Write cache entry in any case.
20  		 */
21  		Put,
22  		/**
23  		 * Write cache entry if no value exists yet.
24  		 */
25  		PutIfAbsent,
26  		/**
27  		 * Replace cached entry if the value differs.
28  		 */
29  		PutIfValueDiffers,
30  		/**
31  		 * Replace cached entry if it existed before.
32  		 */
33  		ReplaceValue
34  	}
35  
36  	/**
37  	 * Cache all key value pairs, using the given mode.
38  	 *
39  	 * @param values the key and value pairs to cache.
40  	 * @param mode   the mode instructing how to apply the values with the cache.
41  	 */
42  	void putAll(Map<? extends K, ? extends V> values, Mode mode);
43  
44  	/**
45  	 * Removes all values for the given keys.
46  	 *
47  	 * @param keys the keys of the values to remove.
48  	 */
49  	void removeAll(Collection<K> keys);
50  
51  	/**
52  	 * Clears the destination.
53  	 */
54  	void clear();
55  
56  	/**
57  	 * Returns true if batching is supported.
58  	 *
59  	 * @return true if batching is supported.
60  	 */
61  	boolean supportsBatching();
62  
63  	/**
64  	 * Starts a new batch operation.
65  	 *
66  	 * @return true if a batch could be opened.
67  	 */
68  	boolean startBatch();
69  
70  	/**
71  	 * Ends a batch operation.
72  	 *
73  	 * @param success if true, the batch completes, otherwise the batch is aborted and changes are not committed.
74  	 */
75  	void endBatch(boolean success);
76  }