ferroui_reactiveui/
rx_cache_size.rs1use std::cell::Cell;
4
5#[cfg(any(target_os = "android", target_os = "ios"))]
7const DEFAULT_SMALL_CACHE_LIMIT: usize = 32;
8#[cfg(any(target_os = "android", target_os = "ios"))]
10const DEFAULT_BIG_CACHE_LIMIT: usize = 64;
11#[cfg(not(any(target_os = "android", target_os = "ios")))]
13const DEFAULT_SMALL_CACHE_LIMIT: usize = 64;
14#[cfg(not(any(target_os = "android", target_os = "ios")))]
16const DEFAULT_BIG_CACHE_LIMIT: usize = 256;
17
18ferroui_system::ferro_thread_local! {
19 static LIMITS: Cell<Option<(usize, usize)>> = const { Cell::new(None) };
21}
22
23pub struct RxCacheSize;
29
30impl RxCacheSize {
31 pub fn small_cache_limit() -> usize {
33 Self::limits().0
34 }
35
36 pub fn big_cache_limit() -> usize {
38 Self::limits().1
39 }
40
41 pub fn initialize(small_cache_limit: usize, big_cache_limit: usize) {
44 LIMITS.with(|limits| {
45 if limits.get().is_none() {
46 limits.set(Some((small_cache_limit, big_cache_limit)));
47 }
48 });
49 }
50
51 #[doc(hidden)]
54 pub fn reset_for_testing() {
55 LIMITS.with(|limits| limits.set(None));
56 }
57
58 fn limits() -> (usize, usize) {
59 LIMITS.with(|limits| match limits.get() {
60 Some(current) => current,
61 None => {
62 let defaults = (DEFAULT_SMALL_CACHE_LIMIT, DEFAULT_BIG_CACHE_LIMIT);
63 limits.set(Some(defaults));
64 defaults
65 }
66 })
67 }
68}