Issue #9190 has been updated by tmm1 (Aman Gupta).


My main use-case for exposing these serials is to collect them automatically before and after each request in a rails app and graph how many times the caches are busted per request.

I would also like to see a Tracepoint or other hook that fires whenever the cache is busted. This would allow capturing a stack trace to see exactly where the cache busting is happening.
----------------------------------------
Feature #9190: Expose serial helper macros
https://bugs.ruby-lang.org/issues/9190#change-43472

Author: simeonwillbanks (Simeon Willbanks)
Status: Feedback
Priority: Normal
Assignee: 
Category: core
Target version: 


I've defined RubyVM::InstructionHelper with singleton methods #method_serial and #constant_serial.  They delegate to helper macros GET_METHOD_SERIAL() and GET_CONSTANT_SERIAL().

With these methods, users have visibility into the method and constant caches.  If it makes sense, I hope this patch is included in Ruby 2.1.0.

def constants_busted?(&blk)
  starting = RubyVM::InstructionHelper.constant_serial
  yield
  ending = RubyVM::InstructionHelper.constant_serial
  ending > starting
end

busted = constants_busted? do
  class Foo; end
end
puts busted.inspect
# true 

https://github.com/ruby/ruby/pull/462.patch

Thanks for considering; any input is appreciated!


-- 
http://bugs.ruby-lang.org/