caching - Grails cache-redis version 1.1.0 插件编译报错

标签 caching grails redis

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

BuildConfig.groovy 编译':缓存: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);
}

最佳答案

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

编译':cache-redis:1.1.2-SNAPSHOT'

关于caching - Grails cache-redis version 1.1.0 插件编译报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45090152/

相关文章:

redis - 通过 create-cluster 脚本在 Mac OS X 上设置 redis 集群

laravel - 队列上的连接名称

python - Asyncio + aiohttp - redis Pub/Sub 和 websocket 在单个处理程序中读/写

grails - 测试资源 Controller 的 UrlMapping 路径

javascript - 如何从Javascript或JQuery获取Grails中的 Action 名称(或 View 名称)

html - 如果缓存日期超过特定日期,则告诉浏览器更新缓存

java - Java中的单例类可以充当缓存机制吗?

grails - IntelliJ IDEA Grails 3.0 错误

nhibernate - Fluent NHibernate Syscache2 缓存过期

html - 如何让浏览器停止缓存服务器响应?