From fbdec0f94655bb30b8d9c1ba4bd2fbad8ae90600 Mon Sep 17 00:00:00 2001
From: Janek <development@superyu.xyz>
Date: Tue, 2 Jan 2024 01:08:25 +0100
Subject: [PATCH] Caching update

- New invalidator: bomb dropped
- Reduce cache lifetime to 10 seconds (down from 3 minutes)
---
 radarflow/src/dma/cache.rs |  2 +-
 radarflow/src/dma/mod.rs   | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/radarflow/src/dma/cache.rs b/radarflow/src/dma/cache.rs
index acac88e..f99825d 100644
--- a/radarflow/src/dma/cache.rs
+++ b/radarflow/src/dma/cache.rs
@@ -18,7 +18,7 @@ pub struct Cache {
 impl Cache {
     pub fn is_valid(&self) -> bool {
         if self.valid {
-            if self.timestamp.elapsed() > std::time::Duration::from_secs(60 * 3) {
+            if self.timestamp.elapsed() > std::time::Duration::from_secs(10) {
                 log::info!("Invalidated cache! Reason: time");
                 return false
             }
diff --git a/radarflow/src/dma/mod.rs b/radarflow/src/dma/mod.rs
index 29cfdae..364cae8 100644
--- a/radarflow/src/dma/mod.rs
+++ b/radarflow/src/dma/mod.rs
@@ -19,6 +19,7 @@ pub async fn run(connector: Connector, pcileech_device: String, data_lock: Arc<R
     let mut last_tickcount = -1;
     let mut last_round = -1;
     let mut last_gamephase = -1;
+    let mut last_bomb_dropped = false;
 
     // Duration for a single tick on 128 ticks. I'm assuming 128 ticks because I don't fucking know how to read the current tickrate off cs2 memory lol
     let target_interval = Duration::from_nanos(SECOND_AS_NANO / 128);
@@ -128,6 +129,15 @@ pub async fn run(connector: Connector, pcileech_device: String, data_lock: Arc<R
                 continue;
             }
 
+            let cur_bomb_dropped = cache.gamerules().bomb_dropped(&mut ctx)?;
+
+            if cur_bomb_dropped != last_bomb_dropped {
+                last_bomb_dropped = cur_bomb_dropped;
+                cache.invalidate();
+                log::info!("Invalidated cache! Reason: bomb drop status changed");
+                continue;
+            }
+
             let cur_tickcount = cache.globals().tick_count(&mut ctx)?;
 
             // New tick, now we want to fetch our data