0
# Distributed Collections
1
2
Redisson provides distributed implementations of standard Java collections that are automatically persisted and synchronized across Redis. These collections maintain the same interfaces as their Java counterparts while providing distributed functionality.
3
4
## Capabilities
5
6
### Maps
7
8
Distributed key-value maps with various caching and persistence strategies.
9
10
```java { .api }
11
/**
12
* Get a distributed map with the specified name
13
* @param name - unique name of the map
14
* @return RMap instance
15
*/
16
public <K, V> RMap<K, V> getMap(String name);
17
18
/**
19
* Get a distributed map with custom codec
20
* @param name - unique name of the map
21
* @param codec - serialization codec
22
* @return RMap instance
23
*/
24
public <K, V> RMap<K, V> getMap(String name, Codec codec);
25
26
/**
27
* Get a distributed map with options
28
* @param options - map configuration options
29
* @return RMap instance
30
*/
31
public <K, V> RMap<K, V> getMap(MapOptions<K, V> options);
32
33
/**
34
* Get a distributed map cache with TTL support
35
* @param name - unique name of the map cache
36
* @return RMapCache instance with expiration capabilities
37
*/
38
public <K, V> RMapCache<K, V> getMapCache(String name);
39
public <K, V> RMapCache<K, V> getMapCache(String name, Codec codec);
40
public <K, V> RMapCache<K, V> getMapCache(MapCacheOptions<K, V> options);
41
42
/**
43
* Get a local cached map for improved read performance
44
* @param name - unique name of the local cached map
45
* @param options - local caching options and strategies
46
* @return RLocalCachedMap instance
47
*/
48
public <K, V> RLocalCachedMap<K, V> getLocalCachedMap(String name, LocalCachedMapOptions<K, V> options);
49
public <K, V> RLocalCachedMap<K, V> getLocalCachedMap(String name, Codec codec, LocalCachedMapOptions<K, V> options);
50
```
51
52
**Map Interfaces:**
53
54
```java { .api }
55
// Standard distributed map
56
public interface RMap<K, V> extends ConcurrentMap<K, V>, RObject, RExpirable {
57
V put(K key, V value);
58
V putIfAbsent(K key, V value);
59
V get(Object key);
60
V remove(Object key);
61
boolean containsKey(Object key);
62
boolean containsValue(Object value);
63
int size();
64
boolean isEmpty();
65
void clear();
66
Set<K> keySet();
67
Collection<V> values();
68
Set<Entry<K, V>> entrySet();
69
70
// Redisson-specific methods
71
V addAndGet(K key, Number delta);
72
Set<K> readAllKeySet();
73
Collection<V> readAllValues();
74
Set<Entry<K, V>> readAllEntrySet();
75
Map<K, V> readAllMap();
76
77
// Fast operations
78
long fastPut(K key, V value);
79
boolean fastPutIfAbsent(K key, V value);
80
long fastRemove(K... keys);
81
}
82
83
// Map with TTL capabilities
84
public interface RMapCache<K, V> extends RMap<K, V> {
85
V put(K key, V value, long ttl, TimeUnit unit);
86
V putIfAbsent(K key, V value, long ttl, TimeUnit unit);
87
V put(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit);
88
89
void expire(long timeToLive, TimeUnit timeUnit);
90
boolean expireAt(long timestamp);
91
void clearExpire();
92
long remainTimeToLive();
93
94
// Entry-level expiration
95
boolean expire(K key, long timeToLive, TimeUnit timeUnit);
96
boolean expireAt(K key, long timestamp);
97
long remainTimeToLive(K key);
98
}
99
100
// Local cached map for improved performance
101
public interface RLocalCachedMap<K, V> extends RMap<K, V> {
102
void preloadCache();
103
void preloadCache(int count);
104
void clearLocalCache();
105
106
// Cache statistics
107
LocalCachedMapStats getCachedMapStats();
108
}
109
```
110
111
**Usage Examples:**
112
113
```java
114
import org.redisson.api.*;
115
import java.util.concurrent.TimeUnit;
116
117
// Basic map operations
118
RMap<String, String> map = redisson.getMap("users");
119
map.put("user1", "Alice");
120
map.put("user2", "Bob");
121
String user = map.get("user1"); // "Alice"
122
123
// Map cache with TTL
124
RMapCache<String, String> cache = redisson.getMapCache("sessions");
125
cache.put("session1", "data", 30, TimeUnit.MINUTES);
126
cache.put("session2", "data", 1, TimeUnit.HOURS, 15, TimeUnit.MINUTES); // TTL + max idle time
127
128
// Local cached map for performance
129
LocalCachedMapOptions<String, String> options = LocalCachedMapOptions.<String, String>defaults()
130
.cacheSize(1000)
131
.timeToLive(10, TimeUnit.MINUTES)
132
.maxIdle(5, TimeUnit.MINUTES);
133
134
RLocalCachedMap<String, String> localCachedMap = redisson.getLocalCachedMap("products", options);
135
localCachedMap.put("product1", "data"); // Cached locally and in Redis
136
```
137
138
### Lists
139
140
Distributed lists maintaining insertion order with indexed access.
141
142
```java { .api }
143
/**
144
* Get a distributed list with the specified name
145
* @param name - unique name of the list
146
* @return RList instance
147
*/
148
public <V> RList<V> getList(String name);
149
public <V> RList<V> getList(String name, Codec codec);
150
public <V> RList<V> getList(PlainOptions options);
151
```
152
153
**List Interface:**
154
155
```java { .api }
156
public interface RList<V> extends List<V>, RObject, RExpirable, RSortable<List<V>> {
157
// Standard List methods
158
boolean add(V element);
159
void add(int index, V element);
160
V get(int index);
161
V set(int index, V element);
162
V remove(int index);
163
boolean remove(Object o);
164
int indexOf(Object o);
165
int lastIndexOf(Object o);
166
int size();
167
boolean isEmpty();
168
void clear();
169
170
// Redisson-specific methods
171
List<V> readAll();
172
void trim(int fromIndex, int toIndex);
173
174
// Range operations
175
List<V> range(int fromIndex);
176
List<V> range(int fromIndex, int toIndex);
177
178
// Fast operations
179
boolean addAll(Collection<? extends V> c);
180
boolean addAll(int index, Collection<? extends V> c);
181
int addAfter(V elementToFind, V element);
182
int addBefore(V elementToFind, V element);
183
184
// Sorting
185
List<V> sort(SortOrder order);
186
List<V> sort(SortOrder order, int offset, int count);
187
List<V> sort(String byPattern, SortOrder order);
188
List<V> sort(String byPattern, List<String> getPatterns, SortOrder order);
189
}
190
```
191
192
**Usage Examples:**
193
194
```java
195
// Basic list operations
196
RList<String> list = redisson.getList("tasks");
197
list.add("Task 1");
198
list.add("Task 2");
199
list.add(1, "Task 1.5"); // Insert at index
200
201
String task = list.get(0); // "Task 1"
202
list.remove(1); // Remove "Task 1.5"
203
204
// Range operations
205
List<String> subset = list.range(0, 5); // Get first 5 elements
206
list.trim(0, 10); // Keep only first 10 elements
207
208
// Sorting
209
list.addAll(Arrays.asList("c", "a", "b"));
210
List<String> sorted = list.sort(SortOrder.ASC); // ["a", "b", "c"]
211
```
212
213
### Sets
214
215
Distributed sets ensuring unique elements.
216
217
```java { .api }
218
/**
219
* Get a distributed set with the specified name
220
* @param name - unique name of the set
221
* @return RSet instance
222
*/
223
public <V> RSet<V> getSet(String name);
224
public <V> RSet<V> getSet(String name, Codec codec);
225
public <V> RSet<V> getSet(PlainOptions options);
226
227
/**
228
* Get a distributed set cache with TTL support
229
* @param name - unique name of the set cache
230
* @return RSetCache instance with expiration capabilities
231
*/
232
public <V> RSetCache<V> getSetCache(String name);
233
public <V> RSetCache<V> getSetCache(String name, Codec codec);
234
235
/**
236
* Get a distributed sorted set
237
* @param name - unique name of the sorted set
238
* @return RSortedSet instance maintaining sort order
239
*/
240
public <V> RSortedSet<V> getSortedSet(String name);
241
public <V> RSortedSet<V> getSortedSet(String name, Codec codec);
242
243
/**
244
* Get a distributed scored sorted set (Redis ZSET)
245
* @param name - unique name of the scored sorted set
246
* @return RScoredSortedSet instance with score-based ordering
247
*/
248
public <V> RScoredSortedSet<V> getScoredSortedSet(String name);
249
public <V> RScoredSortedSet<V> getScoredSortedSet(String name, Codec codec);
250
251
/**
252
* Get a lexicographically sorted set
253
* @param name - unique name of the lex sorted set
254
* @return RLexSortedSet instance with lexicographic ordering
255
*/
256
public RLexSortedSet getLexSortedSet(String name);
257
```
258
259
**Set Interfaces:**
260
261
```java { .api }
262
// Standard distributed set
263
public interface RSet<V> extends Set<V>, RObject, RExpirable, RSortable<Set<V>> {
264
boolean add(V element);
265
boolean remove(Object o);
266
boolean contains(Object o);
267
int size();
268
boolean isEmpty();
269
void clear();
270
Object[] toArray();
271
<T> T[] toArray(T[] a);
272
273
// Redisson-specific methods
274
Set<V> readAll();
275
boolean move(String destination, V member);
276
277
// Set operations
278
Set<V> removeRandom(int amount);
279
V removeRandom();
280
V random();
281
Set<V> random(int count);
282
283
// Union/Intersection
284
int union(String... names);
285
Set<V> readUnion(String... names);
286
int intersection(String... names);
287
Set<V> readIntersection(String... names);
288
int diff(String... names);
289
Set<V> readDiff(String... names);
290
}
291
292
// Sorted set with natural ordering
293
public interface RSortedSet<V> extends SortedSet<V>, RSet<V> {
294
Comparator<? super V> comparator();
295
V first();
296
V last();
297
SortedSet<V> headSet(V toElement);
298
SortedSet<V> tailSet(V fromElement);
299
SortedSet<V> subSet(V fromElement, V toElement);
300
}
301
302
// Scored sorted set (Redis ZSET)
303
public interface RScoredSortedSet<V> extends RObject, RExpirable, RSortable<Collection<V>> {
304
boolean add(double score, V object);
305
boolean addAll(Map<V, Double> objects);
306
307
V first();
308
V last();
309
Double firstScore();
310
Double lastScore();
311
312
Collection<V> valueRange(int startIndex, int endIndex);
313
Collection<ScoredEntry<V>> entryRange(int startIndex, int endIndex);
314
Collection<V> valueRange(double startScore, boolean startScoreInclusive,
315
double endScore, boolean endScoreInclusive);
316
317
Double getScore(V o);
318
int rank(V o);
319
int revRank(V o);
320
321
// Score-based operations
322
Double addScore(V object, Number value);
323
int removeRangeByScore(double startScore, boolean startScoreInclusive,
324
double endScore, boolean endScoreInclusive);
325
int removeRangeByRank(int startIndex, int endIndex);
326
}
327
```
328
329
**Usage Examples:**
330
331
```java
332
// Basic set operations
333
RSet<String> set = redisson.getSet("uniqueUsers");
334
set.add("user1");
335
set.add("user2");
336
set.add("user1"); // Duplicate, won't be added
337
boolean contains = set.contains("user1"); // true
338
339
// Sorted set with scores (leaderboard)
340
RScoredSortedSet<String> leaderboard = redisson.getScoredSortedSet("gameScores");
341
leaderboard.add(1000, "player1");
342
leaderboard.add(1500, "player2");
343
leaderboard.add(800, "player3");
344
345
Collection<String> topPlayers = leaderboard.valueRangeReversed(0, 2); // Top 3 players
346
Double player1Score = leaderboard.getScore("player1"); // 1000.0
347
int player1Rank = leaderboard.revRank("player1"); // Position in leaderboard (0-based)
348
```
349
350
### Queues
351
352
Distributed queues with FIFO ordering and blocking capabilities.
353
354
```java { .api }
355
/**
356
* Get a distributed queue with the specified name
357
* @param name - unique name of the queue
358
* @return RQueue instance
359
*/
360
public <V> RQueue<V> getQueue(String name);
361
public <V> RQueue<V> getQueue(String name, Codec codec);
362
363
/**
364
* Get a blocking queue that blocks on empty queue reads
365
* @param name - unique name of the blocking queue
366
* @return RBlockingQueue instance
367
*/
368
public <V> RBlockingQueue<V> getBlockingQueue(String name);
369
public <V> RBlockingQueue<V> getBlockingQueue(String name, Codec codec);
370
371
/**
372
* Get a deque (double-ended queue) for both ends operations
373
* @param name - unique name of the deque
374
* @return RDeque instance
375
*/
376
public <V> RDeque<V> getDeque(String name);
377
public <V> RDeque<V> getDeque(String name, Codec codec);
378
379
/**
380
* Get a blocking deque
381
* @param name - unique name of the blocking deque
382
* @return RBlockingDeque instance
383
*/
384
public <V> RBlockingDeque<V> getBlockingDeque(String name);
385
public <V> RBlockingDeque<V> getBlockingDeque(String name, Codec codec);
386
387
/**
388
* Get a priority queue with custom ordering
389
* @param name - unique name of the priority queue
390
* @return RPriorityQueue instance
391
*/
392
public <V> RPriorityQueue<V> getPriorityQueue(String name);
393
public <V> RPriorityQueue<V> getPriorityQueue(String name, Codec codec);
394
395
/**
396
* Get a transfer queue for producer-consumer patterns
397
* @param name - unique name of the transfer queue
398
* @return RTransferQueue instance
399
*/
400
public <V> RTransferQueue<V> getTransferQueue(String name);
401
public <V> RTransferQueue<V> getTransferQueue(String name, Codec codec);
402
```
403
404
**Queue Interfaces:**
405
406
```java { .api }
407
// Standard queue interface
408
public interface RQueue<V> extends Queue<V>, RObject, RExpirable {
409
boolean add(V element);
410
boolean offer(V element);
411
V remove();
412
V poll();
413
V element();
414
V peek();
415
416
// Redisson-specific methods
417
List<V> readAll();
418
boolean addAll(Collection<? extends V> c);
419
List<V> poll(int limit);
420
421
// Polling with destination
422
V pollFromAny(long timeout, TimeUnit unit, String... queueNames);
423
Map<String, List<V>> pollFirstAndOfferFirstTo(String queueName, int count, long timeout, TimeUnit unit);
424
}
425
426
// Blocking queue with timeout operations
427
public interface RBlockingQueue<V> extends BlockingQueue<V>, RQueue<V> {
428
void put(V element) throws InterruptedException;
429
boolean offer(V element, long timeout, TimeUnit unit) throws InterruptedException;
430
V take() throws InterruptedException;
431
V poll(long timeout, TimeUnit unit) throws InterruptedException;
432
433
// Multi-queue operations
434
V takeFromAny(String... queueNames) throws InterruptedException;
435
V pollFromAny(long timeout, TimeUnit unit, String... queueNames) throws InterruptedException;
436
437
// Batch operations
438
int drainTo(Collection<? super V> c);
439
int drainTo(Collection<? super V> c, int maxElements);
440
}
441
442
// Double-ended queue
443
public interface RDeque<V> extends Deque<V>, RQueue<V> {
444
void addFirst(V element);
445
void addLast(V element);
446
boolean offerFirst(V element);
447
boolean offerLast(V element);
448
V removeFirst();
449
V removeLast();
450
V pollFirst();
451
V pollLast();
452
V getFirst();
453
V getLast();
454
V peekFirst();
455
V peekLast();
456
457
// Move operations
458
V move(DequeMoveArgs args);
459
}
460
461
// Priority queue with comparator support
462
public interface RPriorityQueue<V> extends Queue<V>, RObject, RExpirable {
463
Comparator<? super V> comparator();
464
boolean trySetComparator(Comparator<? super V> comparator);
465
466
boolean add(V element);
467
boolean offer(V element);
468
V poll();
469
V peek();
470
471
// Bulk operations
472
List<V> readAll();
473
boolean addAll(Collection<? extends V> c);
474
}
475
```
476
477
**Usage Examples:**
478
479
```java
480
// Basic queue operations
481
RQueue<String> queue = redisson.getQueue("tasks");
482
queue.offer("task1");
483
queue.offer("task2");
484
String nextTask = queue.poll(); // "task1" (FIFO)
485
486
// Blocking queue for producer-consumer
487
RBlockingQueue<String> blockingQueue = redisson.getBlockingQueue("jobs");
488
489
// Producer thread
490
blockingQueue.put("job1");
491
blockingQueue.offer("job2", 5, TimeUnit.SECONDS);
492
493
// Consumer thread
494
String job = blockingQueue.take(); // Blocks until element available
495
String jobWithTimeout = blockingQueue.poll(10, TimeUnit.SECONDS);
496
497
// Priority queue with custom ordering
498
RPriorityQueue<Task> priorityQueue = redisson.getPriorityQueue("priorityTasks");
499
priorityQueue.trySetComparator((t1, t2) -> t2.getPriority() - t1.getPriority()); // High priority first
500
priorityQueue.offer(new Task("low", 1));
501
priorityQueue.offer(new Task("high", 10));
502
Task highestPriority = priorityQueue.poll(); // "high" priority task
503
504
// Deque operations
505
RDeque<String> deque = redisson.getDeque("workItems");
506
deque.addFirst("urgent");
507
deque.addLast("normal");
508
String urgent = deque.pollFirst(); // "urgent"
509
String normal = deque.pollLast(); // "normal"
510
```
511
512
### Multimaps
513
514
Distributed multimaps that can store multiple values per key, backed by either lists or sets.
515
516
```java { .api }
517
/**
518
* Get a list-based multimap where each key maps to a list of values
519
* @param name - unique name of the list multimap
520
* @return RListMultimap instance
521
*/
522
public <K, V> RListMultimap<K, V> getListMultimap(String name);
523
public <K, V> RListMultimap<K, V> getListMultimap(String name, Codec codec);
524
public <K, V> RListMultimap<K, V> getListMultimap(PlainOptions options);
525
526
/**
527
* Get a list multimap cache with TTL support
528
* @param name - unique name of the list multimap cache
529
* @return RListMultimapCache instance with expiration capabilities
530
*/
531
public <K, V> RListMultimapCache<K, V> getListMultimapCache(String name);
532
public <K, V> RListMultimapCache<K, V> getListMultimapCache(String name, Codec codec);
533
534
/**
535
* Get a set-based multimap where each key maps to a set of unique values
536
* @param name - unique name of the set multimap
537
* @return RSetMultimap instance
538
*/
539
public <K, V> RSetMultimap<K, V> getSetMultimap(String name);
540
public <K, V> RSetMultimap<K, V> getSetMultimap(String name, Codec codec);
541
public <K, V> RSetMultimap<K, V> getSetMultimap(PlainOptions options);
542
543
/**
544
* Get a set multimap cache with TTL support
545
* @param name - unique name of the set multimap cache
546
* @return RSetMultimapCache instance with expiration capabilities
547
*/
548
public <K, V> RSetMultimapCache<K, V> getSetMultimapCache(String name);
549
public <K, V> RSetMultimapCache<K, V> getSetMultimapCache(String name, Codec codec);
550
```
551
552
**Multimap Interfaces:**
553
554
```java { .api }
555
// List-based multimap allowing duplicate values per key
556
public interface RListMultimap<K, V> extends RObject, RExpirable {
557
int size();
558
boolean isEmpty();
559
boolean containsKey(Object key);
560
boolean containsValue(Object value);
561
boolean containsEntry(Object key, Object value);
562
563
// Adding entries
564
boolean put(K key, V value);
565
boolean putAll(K key, Iterable<? extends V> values);
566
boolean putAll(Multimap<? extends K, ? extends V> multimap);
567
568
// Retrieving values
569
RList<V> get(K key);
570
Collection<V> getAll(K key);
571
RList<V> removeAll(Object key);
572
boolean remove(Object key, Object value);
573
574
// Key and value collections
575
Set<K> keySet();
576
Multiset<K> keys();
577
Collection<V> values();
578
Collection<Entry<K, V>> entries();
579
580
// Fast operations
581
long fastRemove(K... keys);
582
}
583
584
// Set-based multimap ensuring unique values per key
585
public interface RSetMultimap<K, V> extends RObject, RExpirable {
586
int size();
587
boolean isEmpty();
588
boolean containsKey(Object key);
589
boolean containsValue(Object value);
590
boolean containsEntry(Object key, Object value);
591
592
// Adding entries
593
boolean put(K key, V value);
594
boolean putAll(K key, Iterable<? extends V> values);
595
596
// Retrieving values
597
RSet<V> get(K key);
598
Collection<V> getAll(K key);
599
RSet<V> removeAll(Object key);
600
boolean remove(Object key, Object value);
601
602
// Key and value collections
603
Set<K> keySet();
604
Multiset<K> keys();
605
Collection<V> values();
606
Collection<Entry<K, V>> entries();
607
}
608
```
609
610
**Multimap Usage Examples:**
611
612
```java
613
// List multimap - allows duplicate values per key
614
RListMultimap<String, String> listMultimap = redisson.getListMultimap("userRoles");
615
listMultimap.put("user1", "admin");
616
listMultimap.put("user1", "user");
617
listMultimap.put("user1", "admin"); // Duplicate allowed in list multimap
618
619
RList<String> user1Roles = listMultimap.get("user1"); // ["admin", "user", "admin"]
620
Collection<String> allRoles = listMultimap.getAll("user1");
621
622
// Set multimap - unique values per key only
623
RSetMultimap<String, String> setMultimap = redisson.getSetMultimap("userPermissions");
624
setMultimap.put("user1", "read");
625
setMultimap.put("user1", "write");
626
setMultimap.put("user1", "read"); // Duplicate ignored in set multimap
627
628
RSet<String> user1Permissions = setMultimap.get("user1"); // ["read", "write"]
629
630
// Multimap cache with TTL
631
RListMultimapCache<String, String> multimapCache = redisson.getListMultimapCache("sessionData");
632
multimapCache.put("session1", "data1");
633
multimapCache.expireKey("session1", 30, TimeUnit.MINUTES);
634
```
635
636
### Advanced Collections
637
638
Specialized collection types for specific use cases and performance optimization.
639
640
```java { .api }
641
/**
642
* Get a ring buffer with fixed capacity and circular overwriting
643
* @param name - unique name of the ring buffer
644
* @return RRingBuffer instance
645
*/
646
public <V> RRingBuffer<V> getRingBuffer(String name);
647
public <V> RRingBuffer<V> getRingBuffer(String name, Codec codec);
648
649
/**
650
* Get a reliable queue with delivery acknowledgment
651
* @param name - unique name of the reliable queue
652
* @return RReliableQueue instance
653
*/
654
public <V> RReliableQueue<V> getReliableQueue(String name);
655
public <V> RReliableQueue<V> getReliableQueue(String name, Codec codec);
656
657
/**
658
* Get a priority blocking queue with thread-safe operations
659
* @param name - unique name of the priority blocking queue
660
* @return RPriorityBlockingQueue instance
661
*/
662
public <V> RPriorityBlockingQueue<V> getPriorityBlockingQueue(String name);
663
public <V> RPriorityBlockingQueue<V> getPriorityBlockingQueue(String name, Codec codec);
664
665
/**
666
* Get a priority deque supporting both priority ordering and deque operations
667
* @param name - unique name of the priority deque
668
* @return RPriorityDeque instance
669
*/
670
public <V> RPriorityDeque<V> getPriorityDeque(String name);
671
public <V> RPriorityDeque<V> getPriorityDeque(String name, Codec codec);
672
```
673
674
**Advanced Collection Usage Examples:**
675
676
```java
677
// Ring buffer with fixed capacity
678
RRingBuffer<String> ringBuffer = redisson.getRingBuffer("events");
679
ringBuffer.trySetCapacity(100); // Fixed size of 100 elements
680
ringBuffer.add("event1");
681
ringBuffer.add("event2");
682
// When capacity is reached, oldest elements are overwritten
683
684
// Reliable queue with acknowledgment
685
RReliableQueue<String> reliableQueue = redisson.getReliableQueue("importantTasks");
686
reliableQueue.offer("critical-task");
687
688
// Consumer processes with acknowledgment
689
String task = reliableQueue.poll(); // Remove from queue
690
// Process task...
691
// If processing succeeds, task is automatically acknowledged
692
// If JVM crashes before ack, task returns to queue
693
```
694
695
## Collection Options
696
697
```java { .api }
698
// Map configuration options
699
public class MapOptions<K, V> {
700
private MapLoader<K, V> loader;
701
private MapWriter<K, V> writer;
702
private WriteBehindOptions writeBehindOptions;
703
private WriteMode writeMode = WriteMode.WRITE_THROUGH;
704
705
public MapOptions<K, V> loader(MapLoader<K, V> loader);
706
public MapOptions<K, V> writer(MapWriter<K, V> writer);
707
public MapOptions<K, V> writeMode(WriteMode writeMode);
708
public MapOptions<K, V> writeBehind(WriteBehindOptions options);
709
}
710
711
// Map cache configuration with eviction
712
public class MapCacheOptions<K, V> extends MapOptions<K, V> {
713
private EvictionPolicy evictionPolicy = EvictionPolicy.NONE;
714
private int maxSize;
715
private long timeToLiveInMillis;
716
private long maxIdleInMillis;
717
718
public MapCacheOptions<K, V> evictionPolicy(EvictionPolicy evictionPolicy);
719
public MapCacheOptions<K, V> maxSize(int maxSize);
720
public MapCacheOptions<K, V> timeToLive(long timeToLive, TimeUnit timeUnit);
721
public MapCacheOptions<K, V> maxIdle(long maxIdle, TimeUnit timeUnit);
722
}
723
724
// Local cached map options for performance
725
public class LocalCachedMapOptions<K, V> extends MapOptions<K, V> {
726
public enum ReconnectionStrategy { CLEAR, LOAD, NONE }
727
public enum SyncStrategy { INVALIDATE, UPDATE, NONE }
728
729
private ReconnectionStrategy reconnectionStrategy = ReconnectionStrategy.CLEAR;
730
private SyncStrategy syncStrategy = SyncStrategy.INVALIDATE;
731
private int cacheSize = 0;
732
private long timeToLiveInMillis;
733
private long maxIdleInMillis;
734
735
public LocalCachedMapOptions<K, V> cacheSize(int cacheSize);
736
public LocalCachedMapOptions<K, V> timeToLive(long timeToLive, TimeUnit timeUnit);
737
public LocalCachedMapOptions<K, V> maxIdle(long maxIdle, TimeUnit timeUnit);
738
public LocalCachedMapOptions<K, V> reconnectionStrategy(ReconnectionStrategy strategy);
739
public LocalCachedMapOptions<K, V> syncStrategy(SyncStrategy strategy);
740
}
741
```