Created
December 30, 2014 01:10
-
-
Save bitcloud/f6b9312149a8fc70324b to your computer and use it in GitHub Desktop.
Rails: Delayed Memcache invalidation (unseful for heroku deployments)
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
# /config/initializers/00_asset_cache_check.rb | |
currenthash = File.read ".cacheversion" | |
cachehash = Rails.cache.read "cacheversion" | |
puts "Checking cache version: #{cachehash} against slug version: #{currenthash}\n" | |
if currenthash != cachehash | |
puts "flushing cache\n" | |
Rails.cache.clear | |
Rails.cache.write "cacheversion", currenthash | |
else | |
puts "cache ok\n" | |
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
# /lib/tasks/store_asset_cacheversion.rake | |
# add uuidtools to Gemfile | |
require "uuidtools" | |
def storeCacheVersion | |
cacheversion = UUIDTools::UUID.random_create | |
File.open(".cacheversion", "w") { |file| file.write(cacheversion) } | |
end | |
Rake::Task["assets:precompile"].enhance do | |
puts "Storing git hash in file for cache invalidation (assets:precompile)\n" | |
storeCacheVersion | |
end | |
Rake::Task["assets:precompile:nondigest"].enhance do | |
puts "Storing git hash in file for cache invalidation (assets:precompile:nondigest)\n" | |
storeCacheVersion | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment