pub struct GameDataCache {
client: SupabaseClient,
patch: String,
cache_dir: PathBuf,
spells: Cache<i32, SpellDataFlat>,
traits: Cache<i32, TraitTreeFlat>,
items: Cache<i32, ItemDataFlat>,
specs: Cache<i32, SpecDataFlat>,
scaling_data: Cache<(), Arc<ItemScalingData>>,
}Expand description
Three-layer cache (memory, disk, network) for game data keyed by patch version.
Fields§
§client: SupabaseClient§patch: String§cache_dir: PathBuf§spells: Cache<i32, SpellDataFlat>§traits: Cache<i32, TraitTreeFlat>§items: Cache<i32, ItemDataFlat>§specs: Cache<i32, SpecDataFlat>§scaling_data: Cache<(), Arc<ItemScalingData>>Implementations§
Source§impl GameDataCache
impl GameDataCache
pub(super) fn read_disk<T>(
&self,
category: &str,
key: i32,
) -> Result<Option<T>, CacheError>where
T: DeserializeOwned,
pub(super) fn read_disk_or_miss<T>(&self, category: &str, key: i32) -> Option<T>where
T: DeserializeOwned,
pub(super) fn write_disk<T>(
&self,
category: &str,
key: i32,
value: &T,
) -> Result<(), CacheError>where
T: Serialize,
pub(super) fn read_scaling_data_disk_or_miss(&self) -> Option<ItemScalingData>
pub(super) fn write_scaling_data_disk( &self, value: &ItemScalingData, ) -> Result<(), CacheError>
pub(super) fn clear_disk(&self) -> Result<(), CacheError>
pub(super) fn scaling_data_disk_path(&self) -> PathBuf
Sourcepub(super) fn patch_matches(&self) -> Result<bool, CacheError>
pub(super) fn patch_matches(&self) -> Result<bool, CacheError>
Ok(true) on patch match, Ok(false) when no version file exists; a read error returns Err so a transient failure never wipes the cache.
pub(super) fn write_patch_version(&self) -> Result<(), CacheError>
fn disk_path(&self, category: &str, key: i32) -> PathBuf
fn patch_version_path(&self) -> PathBuf
Source§impl GameDataCache
impl GameDataCache
Sourcepub fn new(
client: SupabaseClient,
patch: impl Into<String>,
cache_dir: impl Into<PathBuf>,
) -> Result<Self, CacheError>
pub fn new( client: SupabaseClient, patch: impl Into<String>, cache_dir: impl Into<PathBuf>, ) -> Result<Self, CacheError>
Creates a patch-versioned cache rooted at cache_dir.
§Errors
Returns an error if the cache directory cannot be created.
pub(crate) async fn get_spell( &self, id: i32, ) -> Result<SpellDataFlat, CacheError>
pub(crate) async fn get_spells( &self, ids: &[i32], ) -> Result<Vec<SpellDataFlat>, CacheError>
pub(crate) async fn get_trait_tree( &self, spec_id: i32, ) -> Result<TraitTreeFlat, CacheError>
pub(crate) async fn get_item(&self, id: i32) -> Result<ItemDataFlat, CacheError>
pub(crate) async fn get_spec(&self, id: i32) -> Result<SpecDataFlat, CacheError>
pub(crate) async fn get_scaling_data( &self, ) -> Result<Arc<ItemScalingData>, CacheError>
pub(crate) async fn get_power_types( &self, ) -> Result<Vec<PowerTypeFlat>, CacheError>
pub(crate) fn client(&self) -> &SupabaseClient
async fn read_memory_or_disk<V>( &self, mem_cache: &Cache<i32, V>, disk_category: &str, key: i32, ) -> Option<V>
async fn get_cached<'a, V, F, Fut>(
&'a self,
mem_cache: &Cache<i32, V>,
disk_category: &str,
key: i32,
fetch: F,
) -> Result<V, CacheError>where
V: Clone + Serialize + DeserializeOwned + Send + Sync + 'static,
F: FnOnce(i32) -> Fut,
Fut: Future<Output = Result<V, CacheError>> + 'a,
async fn load_scaling_data(&self) -> Result<Arc<ItemScalingData>, CacheError>
async fn get_single<T>(
&self,
path: &str,
resource: &str,
key: &str,
value: i32,
) -> Result<T, CacheError>where
T: DeserializeOwned,
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GameDataCache
impl !RefUnwindSafe for GameDataCache
impl Send for GameDataCache
impl Sync for GameDataCache
impl Unpin for GameDataCache
impl UnsafeUnpin for GameDataCache
impl !UnwindSafe for GameDataCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more