Last active
December 14, 2015 09:29
-
-
Save eprothro/5065310 to your computer and use it in GitHub Desktop.
A simple rake file with tasks to:
1) clear the rails cache
2) give statistics for a memcache protocol store (e.g., Dalli)
This file contains hidden or 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
| namespace :cache do | |
| task :clear => :environment do | |
| puts "=> Clearning Rails cache..." | |
| Rake::Task["cache:stats"].invoke | |
| puts "\n `Rails.cache.clear` => " + Rails.cache.clear.to_s + "\n\n" | |
| # manually reset the stats, as clearing the cache doesn't do so | |
| Rails.cache.dalli.reset_stats if Rails.cache.try(:dalli).respond_to? :reset_stats | |
| Rake::Task["cache:stats"].reenable | |
| Rake::Task["cache:stats"].invoke | |
| end | |
| task :stats => :environment do | |
| include ActionView::Helpers::NumberHelper | |
| puts "=> Rails cache stats:" | |
| if Rails.cache.respond_to? :stats | |
| Rails.cache.stats.each do |host, stats| | |
| utilization = ( stats['bytes'].to_f / stats['engine_maxbytes'].to_f ) * 100 | |
| puts " #{host}:" | |
| puts " > items: #{stats['total_items']}" | |
| puts " > utilization: #{number_to_human_size(stats['bytes'])} (~#{number_to_percentage(utilization, precision: 0)})" | |
| puts " > evictions: #{stats['evictions']}" | |
| end | |
| else | |
| puts " > unavailable from #{Rails.cache.class}" | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment