Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Handle concurrent routing table fetches.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Dec 3, 2014
1 parent b57abc9 commit 67b987f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions go/vumitools/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def schedule_eviction(self, key):
"""
Schedule the eviction of a cached routing table.
"""
if key in self._evictors:
# We already have an evictor for this routing table, so we don't
# need a new one.
return
delayed_call = self._reactor.callLater(
self._ttl, self.evict_routing_table_entry, key)
self._evictors[key] = delayed_call
Expand All @@ -236,6 +240,11 @@ def get_routing_table(self, user_api):
"""
key = user_api.user_account_key
if key not in self._routing_tables:
# Fetching the routing table returns control to the reactor and
# gives other things the opportunity to cache the routing table
# behind our back. If this happens, we replace the cached table
# (the one we fetched may be newer) and let schedule_eviction()
# worry about the existing evictor.
routing_table = yield user_api.get_routing_table()
if self._ttl <= 0:
# Special case for disabled cache.
Expand Down

0 comments on commit 67b987f

Please sign in to comment.