Class: CacheJSON::Adapters::Redis
- Inherits:
-
Object
- Object
- CacheJSON::Adapters::Redis
- Defined in:
- lib/cache_json/adapters/redis.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #cache_expiring_soon? ⇒ Boolean
- #cached_results ⇒ Object
- #cached_results=(results) ⇒ Object
- #clear_cache! ⇒ Object
-
#initialize(args:, options:) ⇒ Redis
constructor
A new instance of Redis.
Constructor Details
#initialize(args:, options:) ⇒ Redis
Returns a new instance of Redis.
9 10 11 12 |
# File 'lib/cache_json/adapters/redis.rb', line 9 def initialize(args:, options:) @args = args @options = end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
6 7 8 |
# File 'lib/cache_json/adapters/redis.rb', line 6 def args @args end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/cache_json/adapters/redis.rb', line 7 def @options end |
Instance Method Details
#cache_expiring_soon? ⇒ Boolean
34 35 36 |
# File 'lib/cache_json/adapters/redis.rb', line 34 def cache_expiring_soon? $redis.ttl(full_key) < [:refresh][:buffer].to_i end |
#cached_results ⇒ Object
14 15 16 17 18 19 |
# File 'lib/cache_json/adapters/redis.rb', line 14 def cached_results return @cached_results if @cached_results results_json = $redis.get(full_key) @cached_results = JSON.parse(results_json) if results_json end |
#cached_results=(results) ⇒ Object
21 22 23 24 25 |
# File 'lib/cache_json/adapters/redis.rb', line 21 def cached_results=(results) $redis.sadd(class_key, full_key) $redis.set(full_key, results.to_json) $redis.expire(full_key, [:time_to_expire].to_i) end |
#clear_cache! ⇒ Object
27 28 29 30 31 32 |
# File 'lib/cache_json/adapters/redis.rb', line 27 def clear_cache! $redis.smembers(class_key).each do |key| $redis.del(key) end $redis.del(class_key) end |