From 18b17f91e397b13054fcb5f422594e8c6e8e5049 Mon Sep 17 00:00:00 2001 From: kaniini Date: Tue, 8 Jan 2019 05:14:59 +0000 Subject: [PATCH] http signatures: hold actor keys in an LRU cache --- relay/http_signatures.py | 3 +++ requirements.txt | 1 + 2 files changed, 4 insertions(+) diff --git a/relay/http_signatures.py b/relay/http_signatures.py index 0965cfc..81dea8d 100644 --- a/relay/http_signatures.py +++ b/relay/http_signatures.py @@ -7,6 +7,8 @@ from Crypto.PublicKey import RSA from Crypto.Hash import SHA, SHA256, SHA512 from Crypto.Signature import PKCS1_v1_5 +from async_lru import alru_cache + from .remote_actor import fetch_actor @@ -57,6 +59,7 @@ def sign_headers(headers, key, key_id): return ','.join(chunks) +@alru_cache(maxsize=16384) async def fetch_actor_key(actor): actor_data = await fetch_actor(actor) diff --git a/requirements.txt b/requirements.txt index ea34d02..748c6e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,3 +10,4 @@ PyYAML==3.13 simplejson==3.16.0 yarl==1.2.6 cachetools +async_lru