use super::{CLASS_DICT_CACHE, EXTENDS_CHAIN_CACHE, FILE_HASH_CACHE, RESOLVED_CLASS_CACHE};
use std::sync::RwLock;
pub(super) static CACHE_ENABLED: RwLock<bool> = RwLock::new(false);
pub fn enable_cache() {
*CACHE_ENABLED.write().expect("cache enabled lock poisoned") = true;
}
pub fn disable_cache() {
*CACHE_ENABLED.write().expect("cache enabled lock poisoned") = false;
clear_caches();
}
pub fn is_cache_enabled() -> bool {
*CACHE_ENABLED.read().expect("cache enabled lock poisoned")
}
pub fn clear_caches() {
CLASS_DICT_CACHE
.write()
.expect("class dict cache lock poisoned")
.clear();
RESOLVED_CLASS_CACHE
.write()
.expect("resolved class cache lock poisoned")
.clear();
FILE_HASH_CACHE
.write()
.expect("file hash cache lock poisoned")
.clear();
EXTENDS_CHAIN_CACHE
.write()
.expect("extends chain cache lock poisoned")
.clear();
}
pub fn clear_all_caches() {
clear_caches();
}
pub fn get_cache_stats() -> (usize, usize) {
let class_dict_size = CLASS_DICT_CACHE
.read()
.expect("class dict cache lock poisoned")
.len();
let resolved_size = RESOLVED_CLASS_CACHE
.read()
.expect("resolved class cache lock poisoned")
.len();
(class_dict_size, resolved_size)
}