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

org.nutz.plugins.cache.impl.redis.RedisCacheManager Maven / Gradle / Ivy

package org.nutz.plugins.cache.impl.redis;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheManager;
import org.nutz.plugins.cache.CacheSerializer;
import org.nutz.plugins.cache.serializer.DefaultJdkSerializer;

/**
 * 基于 jedis的缓存实现
 * @author wendal
 *
 */
public class RedisCacheManager implements CacheManager {
    
    /**
     * 模式设置.

* kv模式使用get/set组合,支持ttl,内存占用较多.

* hset模式使用hget/hset组合,不支持ttl, 内存占用较少.

*/ protected String mode; /** * 是否输出详细的日志 */ protected boolean debug; /** * 默认过期时间,仅mode=kv时生效 */ protected int ttl; /** * 序列化器,一般不需要管 */ protected CacheSerializer serializer = new DefaultJdkSerializer(); public Cache getCache(String name) { RedisCache cache = null; if (mode == null || !mode.equals("kv")) cache = new RedisCache(); else cache = new RedisCache2(); cache.setName(name).setDebug(debug).setSerializer(serializer).setTtl(ttl); return (Cache) cache; } public void setMode(String mode) { this.mode = mode; } public void init() {} public void depose() {} public void setDebug(boolean debug) { this.debug = debug; } public void setSerializer(CacheSerializer serializer) { this.serializer = serializer; } public void setTtl(int ttl) { this.ttl = ttl; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy