Ruby on Rails and Redis - cache working intermittent -
i using redis cache data in rails, works first time , caches data after 5 mins expires following error
actionview::template::error (undefined method []' true:trueclass):
this use cache data, custom method monkey patched redis class.
@avg_results = $redis.cache( :key => "#{current_member.id}-#{@group.id}-avg", :expire => 300, # seconds, 5 minutes :timeout => 5 # seconds ) group.all.to_json end unless @avg_results.nil? @avg_results = json.load @avg_results end
this monkey patch
class redis def cache(params) key = params[:key] || raise(":key parameter required!") expire = params[:expire] || nil recalculate = params[:recalculate] || nil expire = params[:expire] || nil timeout = params[:timeout] || 0 default = params[:default] || nil if (value = get(key)).nil? || recalculate begin value = timeout::timeout(timeout) { yield(self) } rescue timeout::error value = default end set(key, value) expire(key, expire) if expire value else value end end end
so question this, why , getting error actionview::template::error (undefined method []' true:trueclass):
?
edit
i think have tracked issue down memory leak, if server out of memory when redis has expired , saving new data redis true:trueclass
set? instead of data database. can patch this? or need track down leak?
Comments
Post a Comment