Class: SidekiqSmartCache::Worker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/sidekiq_smart_cache/worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(klass, instance_id, method, args, cache_tag, expires_in) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sidekiq_smart_cache/worker.rb', line 8

def perform(klass, instance_id, method, args, cache_tag, expires_in)
  all_args = [method]
  if args.is_a?(Array)
    all_args += args
  elsif args
    all_args << args
  end
  subject = Object.const_get(klass)
  subject = subject.find(instance_id) if instance_id
  result = subject.send(*all_args)
  Result.persist(cache_tag, result, expires_in)
  redis.send_done_message(cache_tag)
  result
ensure
  # remove the interlock key
  Interlock.new(cache_tag).clear
end