O
Oliver Cat
Hi all,
I've been reading the RailsDispatch blog, and have been looking at this
code.
class BlacklistConstraint
def initialize
@ips = Blacklist.retrieve_ips
@mutex = Mutex.new
@last_update = Time.now
end
def matches?(request)
@mutex.synchronize do
if (Time.now - @last_update) > 3600
@ips = Blacklist.retrieve_ips
@last_update = Time.now
end
end
[email protected]?(request.remote_ip)
end
end
What interests me is the 'matches?' method, specifically the
mutex.synchronize block. I'm wondering what is the benefit of this code,
and how it works?
Is it so other attempts to call Blacklist.retrieve_ips are blocked, and
if so, should the mutex be implemented in the Blacklist class?
thanks for reading.
I've been reading the RailsDispatch blog, and have been looking at this
code.
class BlacklistConstraint
def initialize
@ips = Blacklist.retrieve_ips
@mutex = Mutex.new
@last_update = Time.now
end
def matches?(request)
@mutex.synchronize do
if (Time.now - @last_update) > 3600
@ips = Blacklist.retrieve_ips
@last_update = Time.now
end
end
[email protected]?(request.remote_ip)
end
end
What interests me is the 'matches?' method, specifically the
mutex.synchronize block. I'm wondering what is the benefit of this code,
and how it works?
Is it so other attempts to call Blacklist.retrieve_ips are blocked, and
if so, should the mutex be implemented in the Blacklist class?
thanks for reading.