use std::cell::Cell;
#[cfg(any(target_os = "android", target_os = "ios"))]
const DEFAULT_SMALL_CACHE_LIMIT: usize = 32;
#[cfg(any(target_os = "android", target_os = "ios"))]
const DEFAULT_BIG_CACHE_LIMIT: usize = 64;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
const DEFAULT_SMALL_CACHE_LIMIT: usize = 64;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
const DEFAULT_BIG_CACHE_LIMIT: usize = 256;
ferroui_system::ferro_thread_local! {
static LIMITS: Cell<Option<(usize, usize)>> = const { Cell::new(None) };
}
pub struct RxCacheSize;
impl RxCacheSize {
pub fn small_cache_limit() -> usize {
Self::limits().0
}
pub fn big_cache_limit() -> usize {
Self::limits().1
}
pub fn initialize(small_cache_limit: usize, big_cache_limit: usize) {
LIMITS.with(|limits| {
if limits.get().is_none() {
limits.set(Some((small_cache_limit, big_cache_limit)));
}
});
}
#[doc(hidden)]
pub fn reset_for_testing() {
LIMITS.with(|limits| limits.set(None));
}
fn limits() -> (usize, usize) {
LIMITS.with(|limits| match limits.get() {
Some(current) => current,
None => {
let defaults = (DEFAULT_SMALL_CACHE_LIMIT, DEFAULT_BIG_CACHE_LIMIT);
limits.set(Some(defaults));
defaults
}
})
}
}