cache_money 'nil.repository' error

356 Views Asked by At

I'm just trying out cache_money gem on an existing app and getting this error:

NoMethodError (You have a nil object when you didn't expect it!
The error occurred while evaluating nil.repository)

I think I have my memached server configured properly. I'm using Rails 2.2.2

EDIT:

Stack trace:

NoMethodError (You have a nil object when you didn't expect it!
The error occurred while evaluating nil.repository):
    (__DELEGATION__):2:in `__send__'
    (__DELEGATION__):2:in `repository'
    /usr/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cache_money.rb:50:in `transaction'
    /vendor/rails/activerecord/lib/active_record/transactions.rb:138:in `transaction'
    /vendor/rails/activerecord/lib/active_record/transactions.rb:178:in `with_transaction_returning_status'
    /vendor/rails/activerecord/lib/active_record/transactions.rb:146:in `save_without_trace_ActiveRecord___self_class_name__save'
    /vendor/rails/activerecord/lib/active_record/transactions.rb:158:in `rollback_active_record_state!'
    /vendor/rails/activerecord/lib/active_record/transactions.rb:146:in `save_without_trace_ActiveRecord___self_class_name__save'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/method_tracer.rb:138:in `save_without_trace_ActiveRecord_save'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/method_tracer.rb:41:in `trace_method_execution_with_scope'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/method_tracer.rb:137:in `save_without_trace_ActiveRecord_save'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/method_tracer.rb:141:in `save_without_trace_ActiveRecord_all'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/method_tracer.rb:141:in `save'
    /vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:237:in `create'
    /vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:405:in `create_record'
    /vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:423:in `add_record_to_target_with_callbacks'
    /vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:405:in `create_record'
    /vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:235:in `create'
    /app/controllers/application.rb:234:in `write_audit_log'
    /app/controllers/application.rb:224:in `write_read_audit_log'
    /vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `send'
    /vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `evaluate_method'
    /vendor/rails/activesupport/lib/active_support/callbacks.rb:166:in `call'
    /vendor/rails/actionpack/lib/action_controller/filters.rb:662:in `run_after_filters'
    /vendor/rails/actionpack/lib/action_controller/filters.rb:619:in `call_filters'
    /vendor/rails/actionpack/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
    /vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    /vendor/rails/actionpack/lib/action_controller/rescue.rb:136:in `perform_action_without_caching'
    /vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:13:in `perform_action_without_newrelic_trace'
    /vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
    /vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in `cache'
    /vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:12:in `perform_action_without_newrelic_trace'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:123:in `perform_action'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/method_tracer.rb:41:in `trace_method_execution_with_scope'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:109:in `perform_action'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/method_tracer.rb:18:in `trace_method_execution_no_scope'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:103:in `perform_action'
    /vendor/rails/actionpack/lib/action_controller/base.rb:524:in `send'
    /vendor/rails/actionpack/lib/action_controller/base.rb:524:in `process_without_filters'
    /vendor/rails/actionpack/lib/action_controller/filters.rb:606:in `process_without_session_management_support'
    /vendor/rails/actionpack/lib/action_controller/session_management.rb:134:in `process'
    /vendor/rails/actionpack/lib/action_controller/base.rb:392:in `process'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:183:in `handle_request'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:110:in `dispatch_unlocked'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:123:in `dispatch_without_newrelic'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in `synchronize'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in `dispatch_without_newrelic'
    /vendor/plugins/newrelic_rpm/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb:44:in `dispatch'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi'
    /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:39:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:76:in `process'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:in `synchronize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:in `process'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `orig_process_client'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `orig_process_client'
    /vendor/plugins/spawn/lib/patches.rb:59:in `process_client'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:282:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `each'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in `run'
    /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
    /vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in `load_without_new_constant_marking'
    /vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in `load'
    /vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
    /vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in `load'
    /vendor/rails/railties/lib/commands/servers/mongrel.rb:64
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    /vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
    /vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in `new_constants_in'
    /vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in `require'
    /vendor/rails/railties/lib/commands/server.rb:49
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3
3

There are 3 best solutions below

0
On

If you're using cache_money according to how it's intended to be used (hard to tell from what you've given), it may be a bug in cache_money. There are other nil reference errors reported in the github project, some of which have been resolved since version 0.2.5.

You can check out the latest version of the code as a plugin in your rails project:

script/plugin git://github.com/nkallen/cache-money.git

Perhaps they've fixed your problem since the version you have. If it doesn't help, you can delete the plugin from vendor/plugins/cache-money.

If that doesn't help, you can submit your issue on the author's issue tracker at http://github.com/nkallen/cache-money, and see if they can resolve it for you.

0
On

I'd recommend updating to ngmoco-cache-money's fork, which has incorporated a lot of bugfixes not included in the mainline cache-money repository. http://github.com/ngmoco/cache-money

0
On

I came across this error while using acts_as_taggable_on and cache-money 0.2.5.

I looks like the @cache_config wasn't getting set on the ActsAsTaggableOn::Tag class

if you open up cache-money-0.2.5/lib/cash/config.rb and remove:

   attr_reader :cache_config
   delegate :repository, :indices, :to => :@cache_config

and replace it with:

   def cache_config
     @cache_config ? @cache_config : superclass.cache_config
   end

   delegate :repository, :indices, :to => :cache_config

That will use ActsAsTaggableOn::Tag's superclass's cache_config.

Works for me.