Skip to content

Commit

Permalink
cache Protocol.for_id in memcache
Browse files Browse the repository at this point in the history
for #1149
  • Loading branch information
snarfed committed Jan 15, 2025
1 parent 116d201 commit 2a9f24a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,21 @@ def key_for(cls, id, allow_opt_out=False):

return cls(id=id).key

@staticmethod
def _for_id_memcache_key(id, remote=None):
"""If id is a URL, uses its domain, otherwise returns None.
Args:
id (str)
Returns:
(str domain, bool remote) or None
"""
if remote and util.is_web(id):
return util.domain_from_link(id)

@cached(LRUCache(20000), lock=Lock())
@memcache.memoize(key=_for_id_memcache_key, write=lambda id, remote: remote)
@staticmethod
def for_id(id, remote=True):
"""Returns the protocol for a given id.
Expand Down

0 comments on commit 2a9f24a

Please sign in to comment.