moved configured check into the RedisCache class
This commit is contained in:
parent
fca0ee7c7b
commit
ab8308b9df
4 changed files with 31 additions and 4 deletions
|
|
@ -13,6 +13,13 @@ class RedisCache
|
||||||
@order_field = order_field.to_s
|
@order_field = order_field.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Checks to see if the necessary redis cache variables are set in application.yml
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
def self.configured?
|
||||||
|
AppConfig[:redis_cache].present?
|
||||||
|
end
|
||||||
|
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def cache_exists?
|
def cache_exists?
|
||||||
self.size != 0
|
self.size != 0
|
||||||
|
|
@ -72,7 +79,15 @@ class RedisCache
|
||||||
protected
|
protected
|
||||||
# @return [Redis]
|
# @return [Redis]
|
||||||
def redis
|
def redis
|
||||||
@redis ||= Redis.new
|
@redis ||= Redis.new(:host => RedisCache.redis_host, :port => RedisCache.redis_port)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.redis_host
|
||||||
|
(AppConfig[:redis_location].blank?) ? nil : AppConfig[:redis_location]
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.redis_port
|
||||||
|
(AppConfig[:redis_port].blank?) ? nil : AppConfig[:redis_port]
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ module Diaspora
|
||||||
def visible_post_ids(opts={})
|
def visible_post_ids(opts={})
|
||||||
opts = prep_opts(opts)
|
opts = prep_opts(opts)
|
||||||
|
|
||||||
if AppConfig[:redis_cache] && RedisCache.supported_order?(opts[:order_field]) && opts[:all_aspects?].present?
|
if RedisCache.configured? && RedisCache.supported_order?(opts[:order_field]) && opts[:all_aspects?].present?
|
||||||
cache = RedisCache.new(self, opts[:order_field])
|
cache = RedisCache.new(self, opts[:order_field])
|
||||||
|
|
||||||
cache.ensure_populated!
|
cache.ensure_populated!
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ class Postzord::Receiver
|
||||||
|
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def cache?
|
def cache?
|
||||||
self.respond_to?(:update_cache!) && AppConfig[:redis_cache] &&
|
self.respond_to?(:update_cache!) && RedisCache.configured? &&
|
||||||
@object.respond_to?(:triggers_caching?) && @object.triggers_caching?
|
@object.respond_to?(:triggers_caching?) && @object.triggers_caching?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,5 +161,17 @@ describe RedisCache do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.cache_setup?' do
|
||||||
|
it 'returns true if configuration is properly set' do
|
||||||
|
AppConfig[:redis_cache] = true
|
||||||
|
RedisCache.should be_configured
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false if configuration is not present' do
|
||||||
|
AppConfig[:redis_cache] = false
|
||||||
|
RedisCache.should_not be_configured
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#remove"
|
describe "#remove"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue