user1452701
user1452701

Reputation: 164

Grails cache-redis version 1.1.0 plugin compile error

I added the cache-redis plugin to my Grails 2.5.1 app and compilation fails. Class GrailsRedisCache does not implement method Cache.ValueWrapper putIfAbsent(Object var1, Object var2) from interface org.springframework.cache.Cache. Is there a new Redis cache plugin for Grails 2.5.1 and Cache 1.1.8 plugin?

BuildConfig.groovy compile ':cache:1.1.8' compile "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

Possible implementation of putIfAbsent method.

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

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

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

On GitHub the putIfAbsent() method is implemented. Not sure why the plugin has not been released on 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);
}

Upvotes: 0

Views: 187

Answers (1)

Zachapata
Zachapata

Reputation: 36

cache-redis version 1.1.2-SNAPSHOT has been published and resolves this issue.

compile ':cache-redis:1.1.2-SNAPSHOT'

Upvotes: 1

Related Questions