Skip to content

Instantly share code, notes, and snippets.

@mb-dev
Created February 22, 2013 19:00
Show Gist options
  • Select an option

  • Save mb-dev/5015724 to your computer and use it in GitHub Desktop.

Select an option

Save mb-dev/5015724 to your computer and use it in GitHub Desktop.
Dogpile Effect - read
def custom_read_dogpile(name, timestamp, options)
result = Rails.cache.read(timestamp_key(name, timestamp))
if result.blank?
Rails.cache.write(name + ':refresh-thread', 0, raw: true, unless_exist: true, expires_in: 5.seconds)
if Rails.cache.increment(name + ':refresh-thread') == 1
result = nil
else
result = Rails.cache.read(name + ':last')
end
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment