use bevy::prelude::Resource;
use std::collections::HashSet;
use std::sync::Mutex;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CachePolicy {
UseCache,
ForceRefresh,
}
impl Default for CachePolicy {
fn default() -> Self {
CachePolicy::UseCache
}
}
#[derive(Resource, Default)]
pub struct PersistenceQueryCache {
cache: Mutex<HashSet<u64>>,
}
impl PersistenceQueryCache {
pub fn contains(&self, hash: u64) -> bool {
bevy::log::trace!("PersistenceQueryCache::contains - attempting to lock cache");
let result = self.cache.lock().unwrap().contains(&hash);
bevy::log::trace!(
"PersistenceQueryCache::contains - lock released, result: {}",
result
);
result
}
pub fn insert(&self, hash: u64) {
bevy::log::trace!("PersistenceQueryCache::insert - attempting to lock cache");
self.cache.lock().unwrap().insert(hash);
bevy::log::trace!(
"PersistenceQueryCache::insert - lock released, hash {} inserted",
hash
);
}
}