I know it looks like a silly question , but how am I supposed to fetch some data to ruby object periodically ? or after number of tries ,
Lets say I have :
@variable = SomeModel.all
and I don’t wanna fetch the results all the time so I can do
@variable ||= SomeModel.all
But how am I supposed to do that every periodic time without using something like memcache or 3rd party solution ? Any tricky way to do such a thing ?
Thanks .
untested:
usage:
If
nilis also a valid value, just use a default:no_value_storedas the default when reading from the cache and change the if block.Sidenote: this will likely blow up on you if the keys are too many, as the hash grows indefinitely, so you should clean it up manually or use weak references.