Skip to content

Commit

Permalink
Use scc.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Jul 31, 2024
1 parent f7b4398 commit 534488a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 21 deletions.
14 changes: 0 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ human-sort = "0.2.2"
indexmap = "2.2.6"
miette = "7.2.0"
once_cell = "1.19.0"
once_map = "0.4.18"
regex = { version = "1.10.5", default-features = false, features = ["std"] }
reqwest = { version = "0.12.5", default-features = false, features = [
"charset",
Expand Down
1 change: 0 additions & 1 deletion crates/warpgate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ warpgate_api = { version = "0.9.0", path = "../warpgate-api" }
extism = { workspace = true, features = ["http"] }
miette = { workspace = true }
once_cell = { workspace = true }
once_map = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true, features = ["json", "rustls-tls-native-roots"] }
schematic = { workspace = true, optional = true, features = ["schema"] }
Expand Down
9 changes: 4 additions & 5 deletions crates/warpgate/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::helpers::{from_virtual_path, to_virtual_path};
use crate::id::Id;
use extism::{Error, Function, Manifest, Plugin};
use miette::IntoDiagnostic;
use once_map::OnceMap;
use serde::de::DeserializeOwned;
use serde::Serialize;
use starbase_styles::color::{self, apply_style_tags};
Expand Down Expand Up @@ -67,7 +66,7 @@ pub struct PluginContainer {
pub id: Id,
pub manifest: Manifest,

func_cache: OnceMap<String, Vec<u8>>,
func_cache: Arc<scc::HashMap<String, Vec<u8>>>,
plugin: Arc<RwLock<Plugin>>,
}

Expand Down Expand Up @@ -103,7 +102,7 @@ impl PluginContainer {
manifest,
plugin: Arc::new(RwLock::new(plugin)),
id,
func_cache: OnceMap::new(),
func_cache: Arc::new(scc::HashMap::new()),
})
}

Expand Down Expand Up @@ -135,15 +134,15 @@ impl PluginContainer {
// Check if cache exists already in read-only mode
{
if let Some(data) = self.func_cache.get(&cache_key) {
return self.parse_output(func, data);
return self.parse_output(func, data.get());
}
}

// Otherwise call the function and cache the result
let data = self.call(func, input)?;
let output: O = self.parse_output(func, &data)?;

self.func_cache.insert(cache_key, |_| data);
let _ = self.func_cache.insert(cache_key, data);

Ok(output)
}
Expand Down

0 comments on commit 534488a

Please sign in to comment.