Created
February 20, 2013 21:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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