Skip to content

Instantly share code, notes, and snippets.

@DavidQL
Created February 13, 2012 16:04
Show Gist options
  • Save DavidQL/1817875 to your computer and use it in GitHub Desktop.
Save DavidQL/1817875 to your computer and use it in GitHub Desktop.
class User
def increment_memcache_iterator
Rails.cache.write("user-#{self.id}-memcache-iterator", self.memcache_iterator + 1)
end
def memcache_iterator
# fetch the user's memcache key
# If there isn't one yet, assign it a random integer between 0 and 10
Rails.cache.fetch("user-#{self.id}-memcache-iterator") { rand(10) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment