All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.redisson.spring.cache.RedissonSpringCacheNativeManager Maven / Gradle / Ivy

Go to download

Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC

There is a newer version: 3.40.2
Show newest version
/**
 * 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.spring.cache;

import org.redisson.MapCacheNativeWrapper;
import org.redisson.Redisson;
import org.redisson.api.RMap;
import org.redisson.api.RMapCache;
import org.redisson.api.RMapCacheNative;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.Codec;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.CacheManager;
import org.springframework.context.ResourceLoaderAware;

import java.util.Map;

/**
 * A {@link CacheManager} implementation
 * backed by Redisson instance.
 *
 * @author Nikita Koksharov
 *
 */
@SuppressWarnings("unchecked")
public class RedissonSpringCacheNativeManager extends RedissonSpringCacheManager implements CacheManager, ResourceLoaderAware, InitializingBean {

    /**
     * Creates CacheManager supplied by Redisson instance
     *
     * @param redisson object
     */
    public RedissonSpringCacheNativeManager(RedissonClient redisson) {
        this(redisson, (String) null, null);
    }

    /**
     * Creates CacheManager supplied by Redisson instance and
     * Cache config mapped by Cache name
     *
     * @param redisson object
     * @param config object
     */
    public RedissonSpringCacheNativeManager(RedissonClient redisson, Map config) {
        this(redisson, config, null);
        validateProps();
    }

    /**
     * Creates CacheManager supplied by Redisson instance, Codec instance
     * and Cache config mapped by Cache name.
     * 

* Each Cache instance share one Codec instance. * * @param redisson object * @param config object * @param codec object */ public RedissonSpringCacheNativeManager(RedissonClient redisson, Map config, Codec codec) { super(redisson, config, codec); validateProps(); } /** * Creates CacheManager supplied by Redisson instance * and Cache config mapped by Cache name. *

* Loads the config file from the class path, interpreting plain paths as class path resource names * that include the package path (e.g. "mypackage/myresource.txt"). * * @param redisson object * @param configLocation path */ public RedissonSpringCacheNativeManager(RedissonClient redisson, String configLocation) { this(redisson, configLocation, null); } /** * Creates CacheManager supplied by Redisson instance, Codec instance * and Config location path. *

* Each Cache instance share one Codec instance. *

* Loads the config file from the class path, interpreting plain paths as class path resource names * that include the package path (e.g. "mypackage/myresource.txt"). * * @param redisson object * @param configLocation path * @param codec object */ public RedissonSpringCacheNativeManager(RedissonClient redisson, String configLocation, Codec codec) { super(redisson, configLocation, codec); } private void validateProps() { for (CacheConfig value : configMap.values()) { if (value.getMaxIdleTime() > 0) { throw new UnsupportedOperationException("maxIdleTime isn't supported"); } if (value.getMaxSize() > 0) { throw new UnsupportedOperationException("maxSize isn't supported"); } } } @Override public void setConfig(Map config) { super.setConfig(config); validateProps(); } @Override protected RMap getMap(String name, CacheConfig config) { if (codec != null) { return redisson.getMapCacheNative(name, codec); } return redisson.getMapCacheNative(name); } @Override protected RMapCache getMapCache(String name, CacheConfig config) { RMapCacheNative map = (RMapCacheNative) getMap(name, config); return new MapCacheNativeWrapper<>(map, (Redisson) redisson); } @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); if (configLocation != null) { validateProps(); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy