Delay set cache after response, make cache static

Uses `tokio::spawn` to delay updating the cache while the server responds to the request.

Because `tokio::spawn` can run on another thread, references need to be static, so I initialized the cache in `lazy_static`.
This commit is contained in:
2020-11-07 00:28:54 -05:00
parent 0980d01640
commit a53eeffb0f
11 changed files with 177 additions and 141 deletions

View File

@@ -9,6 +9,10 @@ mod cached_response;
pub use cache::Cache;
pub use cached_response::CachedResponse;
lazy_static! {
pub static ref CACHES: Caches = Caches::initialize();
}
#[derive(Debug, Clone)]
pub struct Caches {
pub owner_ids_by_api_key: Cache<Uuid, i32>,