lib/redis/stream/client.rb in redis-stream-0.1.0 vs lib/redis/stream/client.rb in redis-stream-0.2.0
- old
+ new
@@ -27,11 +27,11 @@
host = options["host"]
port = options["port"]
db = options["db"]
@logger = options["logger"]
- @cache = Redis::Stream::DataCache.new
+ @cache = options.include?('caching') && options['caching'] ? Redis::Stream::DataCache.new : nil
@name = name
@state = Redis::Stream::State::IDLE
@stream = stream_name
@group = group_name
@@ -180,32 +180,34 @@
group = options['group']
type = options['type']
payload = nil
- if options["cache_key"].nil?
- cache_key = @cache.build_key(data)
- if @cache.include?(cache_key)
- if data && data.include?('from_cache') && data['from_cache'].eql?(0)
- @cache.delete(cache_key)
- @logger.info("#{@consumer_id} - invalidating cache with key #{cache_key}")
- else
- payload = {
- type: type,
- from: to,
- from_group: group,
- to: @consumer_id,
- to_group: @group,
- payload: @cache[cache_key].to_json
- }
- @logger.info("#{@consumer_id} - fetching from cache with key #{cache_key}")
- end
+ unless @cache.nil?
+ if options["cache_key"].nil?
+ cache_key = @cache.build_key(data)
+ if @cache.include?(cache_key)
+ if data && data.include?('from_cache') && data['from_cache'].eql?(0)
+ @cache.delete(cache_key)
+ @logger.info("#{@consumer_id} - invalidating cache with key #{cache_key}")
+ else
+ payload = {
+ type: type,
+ from: to,
+ from_group: group,
+ to: @consumer_id,
+ to_group: @group,
+ payload: @cache[cache_key].to_json
+ }
+ @logger.info("#{@consumer_id} - fetching from cache with key #{cache_key}")
+ end
+ end
+ else
+ @cache[options["cache_key"]] = data
end
- else
- @cache[options["cache_key"]] = data
- end
+ end
if payload.nil?
payload = {
type: type,
from: @consumer_id,
from_group: @group,
\ No newline at end of file