Class PutIfAbsentMergePolicy<K,V>
java.lang.Object
com.loomcache.server.wan.merge.PutIfAbsentMergePolicy<K,V>
- Type Parameters:
K- key typeV- value type
- All Implemented Interfaces:
MergePolicy<K,V>
Insert-only merge policy.
Accepts the incoming value only if no existing local value is present. Existing values are never overwritten by incoming WAN events under this policy — useful for immutable caches (e.g., content-addressable storage, precomputed results) where overwrites indicate a bug.
- Since:
- 2.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface MergePolicy
MergePolicy.MergeEntry<V> -
Field Summary
Fields inherited from interface MergePolicy
NO_EXPIRATION_TIME_MILLIS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> @NonNull PutIfAbsentMergePolicy <K, V> instance()Return the shared instance of this stateless policy.merge(@NonNull K key, @NonNull MergePolicy.MergeEntry<V> incoming, @Nullable MergePolicy.MergeEntry<V> existing) Merge an incoming replication entry against the existing local entry.
-
Constructor Details
-
PutIfAbsentMergePolicy
public PutIfAbsentMergePolicy()
-
-
Method Details
-
instance
Return the shared instance of this stateless policy.- Type Parameters:
K- key typeV- value type- Returns:
- a shared
PutIfAbsentMergePolicyinstance
-
merge
public @NonNull Optional<V> merge(@NonNull K key, @NonNull MergePolicy.MergeEntry<V> incoming, @Nullable MergePolicy.MergeEntry<V> existing) Description copied from interface:MergePolicyMerge an incoming replication entry against the existing local entry.- Specified by:
mergein interfaceMergePolicy<K,V> - Parameters:
key- the key being replicated (non-null)incoming- the incoming entry from the remote cluster (non-null)existing- the current local entry, ornullif the key has no local value- Returns:
- the value to keep (non-empty to apply, empty to reject the incoming)
-