Skip to content

Instantly share code, notes, and snippets.

@alexcp
Created February 20, 2013 21:26
Show Gist options
  • Save alexcp/4999782 to your computer and use it in GitHub Desktop.
Save alexcp/4999782 to your computer and use it in GitHub Desktop.
Clear cache DelayJobPaperclip This is a monkey patch to clear a cache after an image is done processing.
module DelayedPaperclip
module Jobs
class DelayedJob
def perform
DelayedPaperclip.process_job(instance_klass, instance_id, attachment_name)
clear_cache(instance_klass, instance_id)
end
def clear_cache(instance_klass, instance_id)
begin
ActionController::Base.new.expire_fragment instance_klass.constantize.find(instance_id).cache_key
rescue NoMethodError
end
end
end
end
end
class User < ActiveRecord::Base
...
# There must be a better way...
# But the it seems I cannot access the hostname within a model
def cache_key
"localhost:3000/#{nickname}"
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment