added acceptable_types to the cache
This commit is contained in:
parent
af5c33f5a5
commit
792647340f
4 changed files with 24 additions and 3 deletions
|
|
@ -45,7 +45,7 @@ class RedisCache
|
|||
|
||||
def populate!
|
||||
# user executes query and gets back hashes
|
||||
sql = @user.visible_posts_sql(:type => AspectStream::TYPES_OF_POST_IN_STREAM, :limit => CACHE_LIMIT, :order => self.order)
|
||||
sql = @user.visible_posts_sql(:type => RedisCache.acceptable_types, :limit => CACHE_LIMIT, :order => self.order)
|
||||
hashes = Post.connection.select_all(sql)
|
||||
|
||||
# hashes are inserted into set in a single transaction
|
||||
|
|
@ -76,6 +76,12 @@ class RedisCache
|
|||
self.trim!
|
||||
end
|
||||
|
||||
# exposing the need to tie cache to a stream
|
||||
# @return [Array<String>] Acceptable Post types for the given cache
|
||||
def self.acceptable_types
|
||||
AspectStream::TYPES_OF_POST_IN_STREAM
|
||||
end
|
||||
|
||||
protected
|
||||
# @return [Redis]
|
||||
def redis
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ class Postzord::Receiver
|
|||
# @return [Boolean]
|
||||
def cache?
|
||||
self.respond_to?(:update_cache!) && RedisCache.configured? &&
|
||||
@object.respond_to?(:triggers_caching?) && @object.triggers_caching?
|
||||
@object.respond_to?(:triggers_caching?) && @object.triggers_caching? &&
|
||||
@object.respond_to?(:type) && RedisCache.acceptable_types.include?(@object.type)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -173,5 +173,12 @@ describe RedisCache do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.acceptable_types' do
|
||||
#exposing the need to tie cache to a stream
|
||||
it 'returns the types from the aspect stream' do
|
||||
RedisCache.acceptable_types.should =~ AspectStream::TYPES_OF_POST_IN_STREAM
|
||||
end
|
||||
end
|
||||
|
||||
describe "#remove"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ describe Postzord::Receiver do
|
|||
before do
|
||||
@receiver.stub(:respond_to?).with(:update_cache!).and_return(true)
|
||||
AppConfig[:redis_cache] = true
|
||||
@receiver.instance_variable_set(:@object, mock(:triggers_caching? => true))
|
||||
|
||||
RedisCache.stub(:acceptable_types).and_return(["StatusMessage"])
|
||||
@receiver.instance_variable_set(:@object, mock(:triggers_caching? => true, :type => "StatusMessage"))
|
||||
end
|
||||
|
||||
it 'returns true if the receiver responds to update_cache and the application has caching enabled' do
|
||||
|
|
@ -66,6 +68,11 @@ describe Postzord::Receiver do
|
|||
@receiver.instance_variable_set(:@object, mock(:triggers_caching? => false))
|
||||
@receiver.cache?.should be_false
|
||||
end
|
||||
|
||||
it 'returns false if the object is not of acceptable type for the cache' do
|
||||
@receiver.instance_variable_set(:@object, mock(:triggers_caching? => true, :type => "Photo"))
|
||||
@receiver.cache?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue