authlogic icon indicating copy to clipboard operation
authlogic copied to clipboard

Caching UserSession.find ?

Open maccman opened this issue 16 years ago • 4 comments

It seems a new user is fetched from the DB whenever I call UserSession.find (which happens at various points). Is there any reason why UserSession.find can't be cached? I guess there could be a callback after the request ends to wipe the cache.

maccman avatar Sep 10 '10 10:09 maccman

Here's the code that does it:

  class << self
    extend ActiveSupport::Memoizable

    def controller=(*args)
      super
      find(:reload)
    end  
    memoize :find
  end

maccman avatar Sep 10 '10 10:09 maccman

Could anyone find an answer to this?

rashilastayntouch avatar Jan 03 '17 08:01 rashilastayntouch

The documentation recommends memoizing this in ApplicationController, which removes the need for a separate caching of UserSession.find in most cases.

def current_user_session
  return @current_user_session if defined?(@current_user_session)
  @current_user_session = UserSession.find
end

villesundberg avatar Jan 03 '17 09:01 villesundberg

Hello, I'm going through old authlogic issues and seeing what to do with them. This one looks a bit like a usage question and a bit like a feature request.

If this is a feature request, it's still relevant, and you are committed to implementing it, please open a new issue and we can discuss your implementation plan.

If this is a usage question, please ask it on stackoverflow. Unfortunatley, we just don't have enough volunteers to handle usage questions on github. Also, please check the reference documentation. You might find something there that's not in the readme.

Thanks!

jaredbeck avatar Jan 23 '18 05:01 jaredbeck