Created
February 22, 2013 19:00
-
-
Save mb-dev/5015724 to your computer and use it in GitHub Desktop.
Dogpile Effect - read
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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