Skip to content

Commit

Permalink
Make the WapmSource local cache timeout configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Jun 16, 2023
1 parent 817705d commit 2d22557
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 5 additions & 2 deletions lib/cli/src/commands/run/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{
collections::{BTreeSet, HashMap},
path::{Path, PathBuf},
sync::{mpsc::Sender, Arc},
time::Duration,
};

use anyhow::{Context, Result};
Expand Down Expand Up @@ -36,6 +37,8 @@ use wasmer_wasix::{

use crate::utils::{parse_envvar, parse_mapdir};

const WAPM_SOURCE_CACHE_TIMEOUT: Duration = Duration::from_secs(10 * 60);

#[derive(Debug, Parser, Clone, Default)]
/// WASI Options
pub struct Wasi {
Expand Down Expand Up @@ -342,8 +345,8 @@ impl Wasi {

let graphql_endpoint = self.graphql_endpoint(wasmer_dir)?;
let cache_dir = WapmSource::default_cache_dir(wasmer_dir);
let wapm_source =
WapmSource::new(graphql_endpoint, Arc::clone(&client)).with_local_cache(cache_dir);
let wapm_source = WapmSource::new(graphql_endpoint, Arc::clone(&client))
.with_local_cache(cache_dir, WAPM_SOURCE_CACHE_TIMEOUT);
source.add_source(wapm_source);

let cache_dir = WebSource::default_cache_dir(wasmer_dir);
Expand Down
10 changes: 4 additions & 6 deletions lib/wasix/src/runtime/resolver/wapm_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ impl WapmSource {
}

/// Cache query results locally.
pub fn with_local_cache(self, cache_dir: impl Into<PathBuf>) -> Self {
pub fn with_local_cache(self, cache_dir: impl Into<PathBuf>, timeout: Duration) -> Self {
WapmSource {
cache: Some(FileSystemCache::new(cache_dir)),
cache: Some(FileSystemCache::new(cache_dir, timeout)),
..self
}
}
Expand Down Expand Up @@ -216,12 +216,10 @@ struct FileSystemCache {
}

impl FileSystemCache {
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10 * 60);

fn new(cache_dir: impl Into<PathBuf>) -> Self {
fn new(cache_dir: impl Into<PathBuf>, timeout: Duration) -> Self {
FileSystemCache {
cache_dir: cache_dir.into(),
timeout: FileSystemCache::DEFAULT_TIMEOUT,
timeout,
}
}

Expand Down

0 comments on commit 2d22557

Please sign in to comment.