|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -98,8 +98,8 @@ public class JCacheCache extends AbstractValueAdaptingCache { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { |
|
|
|
public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { |
|
|
|
boolean set = this.cache.putIfAbsent(key, toStoreValue(value)); |
|
|
|
Object previous = this.cache.invoke(key, PutIfAbsentEntryProcessor.INSTANCE, toStoreValue(value)); |
|
|
|
return (set ? null : get(key)); |
|
|
|
return (previous != null ? toValueWrapper(previous) : null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -125,6 +125,22 @@ public class JCacheCache extends AbstractValueAdaptingCache { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class PutIfAbsentEntryProcessor implements EntryProcessor<Object, Object, Object> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final PutIfAbsentEntryProcessor INSTANCE = new PutIfAbsentEntryProcessor(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
|
|
|
public Object process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException { |
|
|
|
|
|
|
|
Object existingValue = entry.getValue(); |
|
|
|
|
|
|
|
if (existingValue == null) { |
|
|
|
|
|
|
|
entry.setValue(arguments[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return existingValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class ValueLoaderEntryProcessor<T> implements EntryProcessor<Object, Object, T> { |
|
|
|
private class ValueLoaderEntryProcessor<T> implements EntryProcessor<Object, Object, T> { |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|