Grails cache-redis版本1.1.0插件编译错误

时间:2017-07-13 20:14:52

标签: caching grails redis

我在我的Grails 2.5.1应用程序中添加了cache-redis插件,编译失败。 GrailsRedisCache类没有从接口org.springframework.cache.Cache实现Cache.ValueWrapper putIfAbsent(Object var1,Object var2)方法。是否有适用于Grails 2.5.1和Cache 1.1.8插件的新Redis缓存插件?

BuildConfig.groovy 编译':cache:1.1.8' 编译“org.grails.plugins:cache-redis:1.1.0”

.../plugins/cache-redis-1.1.0/src/java/grails/plugin/cache/redis/GrailsRedisCache.java:39: error: GrailsRedisCache is not abstract and does not override abstract method putIfAbsent(Object,Object) in Cache

putIfAbsent方法的可能实现。

@Override
public ValueWrapper putIfAbsent(Object o, Object o1) {
    ValueWrapper val = get(o);

    if (null != val) {
        return val;
    }

    put(o, o1);
    return get(o);
}

在GitHub上实现了putIfAbsent()方法。不确定为什么插件尚未在Grails.org上发布。

@SuppressWarnings("unchecked")
@Override
public ValueWrapper putIfAbsent(final Object key, final Object value) {
    final byte[] k = computeKey(key);
    return (ValueWrapper) template.execute(new RedisCallback<ValueWrapper>() {
        public ValueWrapper doInRedis(RedisConnection connection) throws DataAccessException {
            waitForLock(connection);
            byte[] bs = connection.get(computeKey(key));

            if (bs == null) {
                connection.multi();
                connection.set(k, template.getValueSerializer().serialize(value));
                connection.zAdd(setName, 0, k);

                // Set key time to live when expiration has been configured.
                if (ttl > NEVER_EXPIRE) {
                    connection.expire(k, ttl);
                    connection.expire(setName, ttl);
                }

                connection.exec();
            }

            bs = connection.get(computeKey(key));
            return (bs == null ? null : newValueWrapper(template.getValueSerializer().deserialize(bs)));
        }
    }, true);
}

1 个答案:

答案 0 :(得分:1)

cache-redis版本1.1.2-SNAPSHOT已发布并解决了此问题。

compile ':cache-redis:1.1.2-SNAPSHOT'