Permalink
Browse files

Block-format debug messages

  • Loading branch information...
1 parent cfa3c13 commit ca09414af57aeaa3da9874ec5a5dad112372dbb2 @orslumen committed Sep 17, 2012
View
1 .gitignore
@@ -11,4 +11,5 @@
*.log
*.gem
*.sqlite3
+.idea/**
View
2 lib/record_cache/datastore/active_record_30.rb
@@ -34,7 +34,7 @@ def find_by_sql_with_record_cache(*args)
query = arel ? RecordCache::Arel::QueryVisitor.new.accept(arel.ast) : nil
cacheable = query && record_cache.cacheable?(query)
# log only in debug mode!
- RecordCache::Base.logger.debug("#{cacheable ? 'Fetch from cache' : 'Not cacheable'} (#{query}): SQL = #{sql}") if RecordCache::Base.logger.debug?
+ RecordCache::Base.logger.debug{ "#{cacheable ? 'Fetch from cache' : 'Not cacheable'} (#{query}): SQL = #{sql}" }
# retrieve the records from cache if the query is cacheable otherwise go straight to the DB
cacheable ? record_cache.fetch(query) : find_by_sql_without_record_cache(*args)
end
View
2 lib/record_cache/datastore/active_record_31.rb
@@ -35,7 +35,7 @@ def find_by_sql_with_record_cache(*args)
query = arel ? RecordCache::Arel::QueryVisitor.new(args[1]).accept(arel.ast) : nil
cacheable = query && record_cache.cacheable?(query)
# log only in debug mode!
- RecordCache::Base.logger.debug("#{cacheable ? 'Fetch from cache' : 'Not cacheable'} (#{query}): SQL = #{arel.to_sql}") if RecordCache::Base.logger.debug?
+ RecordCache::Base.logger.debug{ "#{cacheable ? 'Fetch from cache' : 'Not cacheable'} (#{query}): SQL = #{arel.to_sql}" }
# retrieve the records from cache if the query is cacheable otherwise go straight to the DB
cacheable ? record_cache.fetch(query) : find_by_sql_without_record_cache(*args)
end
View
4 lib/record_cache/strategy/full_table_cache.rb
@@ -72,9 +72,7 @@ def from_db(key, version)
# log cache hit/miss to debug log
def log_full_table_cache_hit(key, records)
- hit = records ? "hit" : "miss"
- msg = "FullTableCache #{hit} for model #{@base.name}"
- RecordCache::Base.logger.debug(msg)
+ RecordCache::Base.logger.debug{ "FullTableCache #{records ? 'hit' : 'miss'} for model #{@base.name}" }
end
end
View
2 lib/record_cache/strategy/index_cache.rb
@@ -126,7 +126,7 @@ def increment_version(value, &block)
# log cache hit/miss to debug log
def log_cache_hit(key, ids)
- RecordCache::Base.logger.debug("IndexCache #{ids ? 'hit' : 'miss'} for #{key}: found #{ids ? ids.size : 'no'} ids")
+ RecordCache::Base.logger.debug{ "IndexCache #{ids ? 'hit' : 'miss'} for #{key}: found #{ids ? ids.size : 'no'} ids" }
end
end
end
View
2 lib/record_cache/strategy/request_cache.rb
@@ -47,7 +47,7 @@ def fetch(query, &block)
# log cache hit/miss to debug log
def log_cache_hit(key, hit)
- RecordCache::Base.logger.debug("RequestCache #{hit ? 'hit' : 'miss'} for #{key}")
+ RecordCache::Base.logger.debug{ "RequestCache #{hit ? 'hit' : 'miss'} for #{key}" }
end
end
View
2 lib/record_cache/strategy/unique_index_cache.rb
@@ -113,7 +113,7 @@ def log_id_cache_hit(ids, missing_ids)
hit = missing_ids.empty? ? "hit" : ids.size == missing_ids.size ? "miss" : "partial hit"
missing = missing_ids.empty? || ids.size == missing_ids.size ? "" : ": missing #{missing_ids.inspect}"
msg = "UniqueIndexCache on '#{@attribute}' #{hit} for ids #{ids.size == 1 ? ids.first.inspect : ids.inspect}#{missing}"
- RecordCache::Base.logger.debug(msg)
+ RecordCache::Base.logger.debug{ msg }
end
end
View
6 lib/record_cache/version_store.rb
@@ -27,7 +27,7 @@ def current_multi(id_key_map)
def renew(key)
new_version = (Time.current.to_f * 10000).to_i
@store.write(key, new_version, :raw => true)
- RecordCache::Base.logger.debug("Version Store: renew #{key}: nil => #{new_version}") if RecordCache::Base.logger.debug?
+ RecordCache::Base.logger.debug{ "Version Store: renew #{key}: nil => #{new_version}" }
new_version
end
@@ -38,15 +38,15 @@ def increment(key)
if version.nil? || version == 1
version = renew(key)
else
- RecordCache::Base.logger.debug("Version Store: incremented #{key}: #{version - 1} => #{version}") if RecordCache::Base.logger.debug?
+ RecordCache::Base.logger.debug{ "Version Store: incremented #{key}: #{version - 1} => #{version}" }
end
version
end
# Delete key from the version store (records cached in the Record Store belonging to this key will become unreachable)
def delete(key)
deleted = @store.delete(key)
- RecordCache::Base.logger.debug("Version Store: deleted #{key}") if RecordCache::Base.logger.debug?
+ RecordCache::Base.logger.debug{ "Version Store: deleted #{key}" }
deleted
end

0 comments on commit ca09414

Please sign in to comment.