Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Caching models with associations in AuthenticatedSystem
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
fightinjoe  
View profile  
 More options Feb 6 2007, 2:31 am
From: "fightinjoe" <fightin...@gmail.com>
Date: Mon, 05 Feb 2007 23:31:05 -0800
Local: Tues, Feb 6 2007 2:31 am
Subject: Caching models with associations in AuthenticatedSystem
In my simple app, I've got two models: users and groups.  There is a
habtm relationship between the two.

I've setup caching for both.  The setup includes the associations.
For example:

class User < ActiveRecord::Base
  has_and_belongs_to_many :groups
  acts_as_cached :include => [ :groups ]
  ...
end

I'm using AuthenticatedSystem for logging in users and I want to
replace the User.find calls with User.get_cache.

When I do this, I get the following error:

ArgumentError in GeneralController#index: undefined class/module Group

I believe this error is called because Marshal doesn't know about the
Group class.  If I reference Group prior to the cache call, then
everything works fine.  For example:

Group and User.get_cache( session[:user_id] )

Before I start trying to figure out Rails's auto-include hooks, does
anyone have any insight as to a better way to deal with this issue?

Cheers,

Aaron Wheeler


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Wanstrath  
View profile  
 More options Feb 6 2007, 2:54 am
From: "Chris Wanstrath" <ch...@ozmm.org>
Date: Mon, 5 Feb 2007 23:54:08 -0800
Local: Tues, Feb 6 2007 2:54 am
Subject: Re: Caching models with associations in AuthenticatedSystem
On 2/5/07, fightinjoe <fightin...@gmail.com> wrote:

> When I do this, I get the following error:

> ArgumentError in GeneralController#index: undefined class/module Group

> Before I start trying to figure out Rails's auto-include hooks, does
> anyone have any insight as to a better way to deal with this issue?

This is interesting because acts_as_cached has code to trigger Rails'
autoloading in the situation you describe.  Specifically:

http://require.errtheblog.com/plugins/browser/cache_fu/lib/acts_as_ca...

The "autoload_missing_constants" method (yes I know this is cache_fu
but the principle is the same, just cleaner in this version) should
load Group if it doesn't exist.

However, the error generated when Group is not found usually comes
from Memcache.

Can you send more information on your environment?  Version of Rails,
version of Ruby, version of memcache-client, revision of
acts_as_cached (if you know), and, finally, perhaps the
GeneralController#index code?

Thanks.

--
Chris Wanstrath
http://errtheblog.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fightinjoe  
View profile  
 More options Feb 6 2007, 3:57 am
From: "fightinjoe" <fightin...@gmail.com>
Date: Tue, 06 Feb 2007 08:57:31 -0000
Local: Tues, Feb 6 2007 3:57 am
Subject: Re: Caching models with associations in AuthenticatedSystem
Chris, I switched to cache_fu and still had the same problem.

I'm using Rails 1.2.1, Ruby 1.8.4, memcache-client 1.2.1, and I
checked out cache_fu today.

The general controller isn't doing anything funky:

++++++++++++++++++++++++++++++

class GeneralController < ApplicationController
  before_filter :login_required

  def index
    @user = current_user
  end
end

++++++++++++++++++++++++++++++

current_user comes from authentication_system.  The following is the
main line where current_user is being found:

++++++++++++++++++++++++++++++

def logged_in?
  (@current_user ||= session[:user] ?
User.get_cache(session[:user]) : :false).is_a?(User)
end

++++++++++++++++++++++++++++++

I was able to get the autoloading working when I did the following to
line 56 of /lib/acts_as_cached/cache_methods.rb:

++++++++++++++++++++++++++++++

rescue ArgumentError, MemCache::MemCacheError => error

++++++++++++++++++++++++++++++

If you're curious, here is the backtrace where things start to go
wrong:

++++++++++++++++++++++++++++++

lib/ruby/gems/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb:904:in
`load'
lib/ruby/gems/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb:904:in
`restore'
lib/ruby/gems/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb:805:in
`fetch'
lib/ruby/gems/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb:1035:in
`send'
lib/ruby/gems/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb:1017:in
`send'
lib/ruby/gems/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb:795:in
`fetch'
lib/ruby/gems/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb:926:in
`add_stat'
lib/ruby/gems/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb:783:in
`fetch'
lib/ruby/gems/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb:345:in
`get'
lib/ruby/1.8/sync.rb:229:in `synchronize'
lib/ruby/gems/1.8/gems/Ruby-MemCache-0.0.1/lib/memcache.rb:344:in
`get'
#{RAILS_ROOT}/vendor/plugins/cache_fu/lib/acts_as_cached/
cache_methods.rb:50:in `fetch_cache_without_benchmarking'
#{RAILS_ROOT}/vendor/plugins/cache_fu/lib/acts_as_cached/
cache_methods.rb:55:in `autoload_missing_constants'
#{RAILS_ROOT}/vendor/plugins/cache_fu/lib/acts_as_cached/
cache_methods.rb:49:in `fetch_cache_without_benchmarking'
#{RAILS_ROOT}/vendor/plugins/cache_fu/lib/acts_as_cached/
benchmarking.rb:30:in `fetch_cache'
#{RAILS_ROOT}/vendor/plugins/cache_fu/lib/acts_as_cached/
benchmarking.rb:18:in `cache_benchmark'
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/
benchmarking.rb:37:in `silence'
#{RAILS_ROOT}/vendor/plugins/cache_fu/lib/acts_as_cached/
benchmarking.rb:18:in `cache_benchmark'
/lib/ruby/1.8/benchmark.rb:293:in `measure'
/lib/ruby/1.8/benchmark.rb:307:in `realtime'
#{RAILS_ROOT}/vendor/plugins/cache_fu/lib/acts_as_cached/
benchmarking.rb:17:in `cache_benchmark'
#{RAILS_ROOT}/vendor/plugins/cache_fu/lib/acts_as_cached/
benchmarking.rb:29:in `fetch_cache'
#{RAILS_ROOT}/vendor/plugins/cache_fu/lib/acts_as_cached/
cache_methods.rb:18:in `get_cache'
#{RAILS_ROOT}/lib/authenticated_system.rb:6:in `logged_in?'
#{RAILS_ROOT}/lib/authenticated_system.rb:83:in `login_required'

On Feb 6, 4:54 pm, "Chris Wanstrath" <c...@ozmm.org> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Wanstrath  
View profile  
 More options Feb 6 2007, 7:04 pm
From: "Chris Wanstrath" <ch...@ozmm.org>
Date: Tue, 6 Feb 2007 16:04:53 -0800
Local: Tues, Feb 6 2007 7:04 pm
Subject: Re: Caching models with associations in AuthenticatedSystem
On 2/6/07, fightinjoe <fightin...@gmail.com> wrote:

> I'm using Rails 1.2.1, Ruby 1.8.4, memcache-client 1.2.1, and I
> checked out cache_fu today.

Looks like you're actually using Ruby-MemCache-0.0.1, not
memcache-client (according to the backtrace).

You might have both installed?  I should probably make init.rb require
memcache-client or something.  Here we include it in our
config/environment.rb.

> I was able to get the autoloading working when I did the following to
> line 56 of /lib/acts_as_cached/cache_methods.rb:

> ++++++++++++++++++++++++++++++

> rescue ArgumentError, MemCache::MemCacheError => error

Either way, I'm going to go ahead and add this in.  I expect there
will probably be some other bugs you encounter due to discrepencies
between memcache-client and Ruby-Memcache.  Let me know which ones you
run across.

http://require.errtheblog.com/plugins/changeset/101

Thanks.

--
Chris Wanstrath
http://errtheblog.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »