Skip to main content

Module cache

Module cache 

Source
Expand description

The caching feature of mlb-api

Some requests (especially MetaRequests) are great candidates for a cache since their contents do not change.

Because of this, many types implement Requestable and RequestableEntrypoint such that they can be accessed easily from within the code.

Types like NamedPosition can benefit even more than Person due to their ability to be cached more aggressively. By enabling the aggressive_cache feature, and or calling precache at the start of your main fn. You can cache these values in advance to make their lookups extremely fast.

Note that even without the cache feature, some of this module is still accessible, making requests just… not cache, and instead act as another lookup.

§Examples

use mlb_api::person::PersonId;

let person: PersonId = 660_271.into();
// dbg!(&person.full_name); // person.full_name does not exist

let person: Arc<Person> = person.as_complete_or_request().await.unwrap();
dbg!(&person.full_name);
use mlb_api::meta::NamedPosition;

let position: NamedPosition = NamedPosition { ..Default::default() }; // very common type to see

let position: Arc<Position> = position.as_complete_or_request().await.unwrap();
dbg!(&position.short_name);

Structs§

CacheTable
Type representing the cached values of T; stored as static using Arc<RwLock<_>>

Enums§

Error
Errors for as_complete_or_request calls.

Traits§

Requestable
A type that can be requested via a URL, such as a Position, Award, or Team.
RequestableEntrypoint
A type in which it can be as_complete_or_requested into it’s Complete type.

Functions§

precache
Caches popular types for Requestable use.