class Storyblok::Cache::Redis
Constants
- DEFAULT_CONFIGURATION
Public Class Methods
new(*args)
click to toggle source
# File lib/storyblok/cache/redis.rb, line 8 def initialize(*args) options = args.last.is_a?(::Hash) ? args.pop : {} @redis = options.delete(:redis) || begin if defined?(::Redis) ::Redis.current else raise "Redis.current could not be found. Supply :redis option or make sure Redis.current is available." end end @options = DEFAULT_CONFIGURATION.merge(options) end
Public Instance Methods
cache(key, expire = nil) { |self| ... }
click to toggle source
# File lib/storyblok/cache/redis.rb, line 22 def cache(key, expire = nil) if expire == 0 return yield(self) end expire ||= @options[:ttl] if (value = get(key)).nil? value = yield(self) set(key, value, expire) end value end
get(key)
click to toggle source
# File lib/storyblok/cache/redis.rb, line 37 def get(key) @redis.get(key) end
set(key, value, expire = false)
click to toggle source
# File lib/storyblok/cache/redis.rb, line 41 def set(key, value, expire = false) if expire @redis.setex(key, expire, value) else @redis.set(key, value) end end