moved configured check into the RedisCache class

This commit is contained in:
Ilya Zhitomirskiy 2011-10-04 15:45:49 -07:00
parent fca0ee7c7b
commit ab8308b9df
4 changed files with 31 additions and 4 deletions

View file

@ -13,6 +13,13 @@ class RedisCache
@order_field = order_field.to_s
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]
def cache_exists?
self.size != 0
@ -72,7 +79,15 @@ class RedisCache
protected
# @return [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
# @return [String]

View file

@ -24,7 +24,7 @@ module Diaspora
def visible_post_ids(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.ensure_populated!

View file

@ -14,8 +14,8 @@ class Postzord::Receiver
# @return [Boolean]
def cache?
self.respond_to?(:update_cache!) && AppConfig[:redis_cache] &&
@object.respond_to?(:triggers_caching?) && @object.triggers_caching?
self.respond_to?(:update_cache!) && RedisCache.configured? &&
@object.respond_to?(:triggers_caching?) && @object.triggers_caching?
end
end

View file

@ -161,5 +161,17 @@ describe RedisCache do
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"
end