Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Cache Key with updated_at #81

dewski opened this Issue · 5 comments

6 participants


I realized using cache_key on any Authlogic based model will never really cache, because the updated_at attribute is always changing per refresh.

Here is the SQL that seems to be updating the user on refresh
UPDATE users SET updated_at = '2009-12-14 15:30:50', perishable_token = '6S-x8Qoy-18BaLadImBG', last_request_at = '2009-12-14 15:30:50' WHERE id = 7

Is there any way to remove the updated_at attribute from this?


ya...this is by far the most annoying thing about authlogic




After reading this post I added the following code to my Authlogic authentic model.

Please note that this code works for me in Rails 2, haven't tested it in later versions.

# Save the original class level inherited record timestamps value
alias_method :class_record_timestamps, :record_timestamps
# Gets the instance level record timestamps or fallback to the original value
def record_timestamps; defined?(@instance_record_timestamps) ? @instance_record_timestamps : class_record_timestamps; end
# Set the instance level record timestamps value
def record_timestamps=(value); @instance_record_timestamps = value; end

# Save the original save without session maintenance method
alias_method :orig_save_without_session_maintenance, :save_without_session_maintenance

# Override the save_without_session_maintenance method and wrap the save with
# disabling the record_timestamps on update.
def save_without_session_maintenance(*args)
  self.record_timestamps = false
  self.record_timestamps = nil

@guzart nice. I think this wouldn't work in Rails 4 because of a regression, but there's another way you might do it:

  def should_record_timestamps?
    changed_keys = self.changes.keys - ["last_request_at", "perishable_token", "updated_at", "created_at"]
    changed_keys.present? && super

I also overwrite my User#reset_perishable_token method such that it refreshes less often.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.