pub struct CachedClient<T>{ /* private fields */ }
Expand description
Thread-safe cache wrapper for a QueueTimesClient
.
§Details
The cached client will only hit the API every five minutes, as that is the rate that the queue times website updates wait times. This means that this client is far more efficient if large numbers of requests are made to the API, such as when being used in a server. The internal state and thread-safe nature do however add considerable overhead in scenarios where only occasional calls are made, so a choice must be made depending on your use case.
The implimentation will eagerly return results, but lazaly updates cache. This means that if the client is never called, then it will never update the cache. But if it does need to update the cache, it will first return the result of the request, while the cache updates in the background.
§Example
use queue_times::client::{Client, QueueTimesClient, CachedClient};
let client = Client::new();
let client = CachedClient::new(client); //The only added line!
let parks = client.get_park_urls().await?;
let cedar_point_waits = client.get_ride_times(parks.get("Cedar Point")?.to_owned()).await?;
let mille_wait = cedar_point_waits.iter().find(|r| r.name == "Millennium Force").unwrap();
println!("The current wait for Millennium Force is: {:?}", mille_wait.status)