lib/interlock/interlock.rb in interlock-1.3 vs lib/interlock/interlock.rb in interlock-1.4

- old
+ new

@@ -74,38 +74,51 @@ # # Add each key with scope to the appropriate dependencies array. # def register_dependencies(dependencies, key) + return if Interlock.config[:disabled] + Array(dependencies).each do |klass, scope| - dep_key = dependency_key(klass) - + dep_key = dependency_key(klass, scope, key) + # Get the value for this class/key out of the global store. this = (CACHE.get(dep_key) || {})[key] # Make sure to not overwrite broader scopes. unless this == :all or this == scope # We need to write, so acquire the lock. CACHE.lock(dep_key) do |hash| Interlock.say key, "registered a dependency on #{klass} -> #{scope.inspect}." (hash || {}).merge({key => scope}) end - end - + end end end def say(key, msg, type = "fragment") #:nodoc: - RAILS_DEFAULT_LOGGER.warn "** #{type} #{key.inspect[1..-2]} #{msg}" + log "** #{type} #{key.inspect[1..-2]} #{msg}" end - + + def log(msg) + case Interlock.config[:log_level] + when 'debug', 'info', 'warn', 'error' + log_method = Interlock.config[:log_level] + else + log_method = :debug + end + + RAILS_DEFAULT_LOGGER.send( log_method, msg ) + end + # # Get the Memcached key for a class's dependency list. We store per-class # to reduce lock contention. # - def dependency_key(klass) - "interlock:#{ENV['RAILS_ASSET_ID']}:dependency:#{klass.name}" + def dependency_key(klass, scope, key) + id = (scope == :id ? ":#{key.field(4)}" : nil) + "interlock:#{ENV['RAILS_ASSET_ID']}:dependency:#{klass.name}#{id}" end # # Build a fragment key for an explicitly passed context. Shouldn't be called # unless you need to write your own fine-grained invalidation rules. Make sure @@ -133,11 +146,10 @@ # Invalidate a particular key. # def invalidate(key) # Console and tests do not install the local cache Interlock.local_cache.delete(key) if Interlock.local_cache + ActionController::Base.cache_store.delete key + end - ActionController::Base.fragment_cache_store.delete key - end - end end