def memoizeHashField()

in plugin/src/main/groovy/grails/plugins/redis/RedisService.groovy [201:219]


    def memoizeHashField(String key, String field, Map options = [:], Closure closure) {
        def result = withOptionalRedis { Jedis redis ->
            if (redis) return redis.hget(key, field)
        }

        if (!result) {
            log.debug('cache miss: {}.{}', key, field)
            result = closure()
            if (result) withOptionalRedis { Jedis redis ->
                if (redis) {
                    redis.hset(key, field, result as String)
                    if (options?.expire && redis.ttl(key) == NO_EXPIRATION_TTL) redis.expire(key, options.expire)
                }
            }
        } else {
            log.debug('cache hit : {}.{} = {}', key, field, result)
        }
        result
    }