Feature - RedissonCacheNative implementation added for Mybatis cache.

pull/5994/head
Nikita Koksharov 8 months ago
parent 7c38ca6790
commit b4c96722b0

@ -52,7 +52,7 @@ public class RedissonCache implements Cache {
@Override
public void putObject(Object o, Object o1) {
check();
mapCache.put(o, o1, timeToLive, TimeUnit.MILLISECONDS, maxIdleTime, TimeUnit.MILLISECONDS);
mapCache.fastPut(o, o1, timeToLive, TimeUnit.MILLISECONDS, maxIdleTime, TimeUnit.MILLISECONDS);
}
@Override

@ -0,0 +1,51 @@
/**
* Copyright (c) 2013-2024 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.mybatis;
import org.redisson.MapCacheNativeWrapper;
import org.redisson.Redisson;
import org.redisson.api.RMapCache;
import org.redisson.api.RMapCacheNative;
import org.redisson.api.RedissonClient;
/**
*
* @author Nikita Koksharov
*
*/
public class RedissonCacheNative extends RedissonCache {
public RedissonCacheNative(String id) {
super(id);
}
@Override
public void setMaxIdleTime(long maxIdleTime) {
throw new IllegalArgumentException("maxIdleTime setting isn't supported");
}
@Override
public void setMaxSize(int maxSize) {
throw new IllegalArgumentException("maxSize setting isn't supported");
}
@Override
protected RMapCache<Object, Object> getMapCache(String id, RedissonClient redisson) {
RMapCacheNative<Object, Object> cache = redisson.getMapCacheNative(id);
return new MapCacheNativeWrapper<>(cache, (Redisson) redisson);
}
}

@ -0,0 +1,66 @@
/**
* Copyright (c) 2013-2024 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson;
import org.redisson.api.RMapCacheNative;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
public class MapCacheNativeWrapper<K, V> extends RedissonMapCache<K, V> {
private final RMapCacheNative<K, V> cache;
public MapCacheNativeWrapper(RMapCacheNative<K, V> cache, Redisson redisson) {
super(null, redisson.getCommandExecutor(), "", null, null, null);
this.cache = cache;
}
@Override
public V getWithTTLOnly(K key) {
return cache.get(key);
}
@Override
public boolean fastPut(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) {
return cache.fastPut(key, value, Duration.ofMillis(ttlUnit.toMillis(ttl)));
}
@Override
public V putIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) {
return cache.putIfAbsent(key, value, Duration.ofMillis(ttlUnit.toMillis(ttl)));
}
@Override
public boolean containsKey(Object key) {
return cache.containsKey(key);
}
@Override
public void clear() {
cache.clear();
}
@Override
public long fastRemove(K... keys) {
return cache.fastRemove(keys);
}
@Override
public void destroy() {
cache.destroy();
}
}
Loading…
Cancel
Save