Skip to content

Commit

Permalink
Fixed the remote cache and delayed cache fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Mar 18, 2010
1 parent 4efb974 commit 77096da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions app/controllers/paragraph_renderer.rb
Expand Up @@ -617,15 +617,14 @@ def renderer_cache(obj=nil,display_string=nil,options={ },&block)
# Fetch a element from the remote cache
def delayed_cache_fetch(obj,method,args={},display_string=nil,options={ })
expiration = options[:expires] || 120 # Default to two minutes
display_string = "Tester2#{paragraph.id}_#{display_string}"
display_string = "#{paragraph.id}_#{display_string}"
result = nil

result = DataCache.get_remote("Paragraph",paragraph.id.to_s,display_string)
result, expiration = DataCache.get_remote("Paragraph",paragraph.id.to_s,display_string)
now = Time.now


if result
return DefaultsHashObject.new(result[0])
if result && expiration && expiration > now
return DefaultsHashObject.new(result)
end

remote_args = args.merge( :remote_type => 'Paragraph', :remote_target => paragraph.id.to_s, :display_string => display_string, :expiration => expiration )
Expand All @@ -642,8 +641,8 @@ def delayed_cache_fetch(obj,method,args={},display_string=nil,options={ })

# if we don't have an expired or we are expired and not in the editor
# kick of the worker and put the current results in the cache to be updated
if !result
DataCache.put_remote("Paragraph",paragraph.id.to_s,display_string,[ result ],expiration.to_i)
if !result || !expiration || expiration <= now
DataCache.put_remote("Paragraph",paragraph.id.to_s,display_string,[ result, now + expiration.to_i.seconds ])
logger.warn("Running Delayed worker: #{display_string}")
if obj.is_a?(Class)
DomainModel.run_worker(obj.to_s,nil,method,remote_args)
Expand All @@ -652,7 +651,7 @@ def delayed_cache_fetch(obj,method,args={},display_string=nil,options={ })
end
end

return result[0] if result
return result if result
end


Expand Down
2 changes: 1 addition & 1 deletion app/models/domain_model.rb
Expand Up @@ -663,7 +663,7 @@ def generate_url(field,value)
# Put something into the remote cache from a delayed worker
def self.remote_cache_put(args,result)
now = Time.now
DataCache.put_remote(args[:remote_type],args[:remote_target],args[:display_string],[ result ],args[:expiration].to_i)
DataCache.put_remote(args[:remote_type],args[:remote_target],args[:display_string],[ result ,now + args[:expiration].to_i.seconds])
DataCache.expire_content(args[:remote_type],args[:remote_target])
end

Expand Down

0 comments on commit 77096da

Please sign in to comment.