Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ pub trait Storage: Send + Sync {
/// Get the storage location.
fn location(&self) -> String;

/// Get the cache backend type name (e.g., "disk", "redis", "s3").
/// Used for statistics and display purposes.
fn cache_type_name(&self) -> &'static str {
"unknown"
}

/// Get the current storage usage, if applicable.
async fn current_size(&self) -> Result<Option<u64>>;

Expand Down Expand Up @@ -470,6 +476,7 @@ impl PreprocessorCacheModeConfig {
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
pub struct RemoteStorage {
operator: opendal::Operator,
Expand All @@ -485,6 +492,7 @@ pub struct RemoteStorage {
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
impl RemoteStorage {
pub fn new(operator: opendal::Operator, basedirs: Vec<Vec<u8>>) -> Self {
Expand All @@ -502,6 +510,7 @@ impl RemoteStorage {
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
#[async_trait]
impl Storage for RemoteStorage {
Expand Down Expand Up @@ -585,6 +594,12 @@ impl Storage for RemoteStorage {
)
}

fn cache_type_name(&self) -> &'static str {
// Use opendal's scheme as the cache type name
// This returns "s3", "redis", "azure", "gcs", etc.
self.operator.info().scheme()
}

async fn current_size(&self) -> Result<Option<u64>> {
Ok(None)
}
Expand Down
28 changes: 28 additions & 0 deletions src/cache/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ impl Storage for DiskCache {
format!("Local disk: {:?}", self.lru.lock().unwrap().path())
}

fn cache_type_name(&self) -> &'static str {
"disk"
}

async fn current_size(&self) -> Result<Option<u64>> {
Ok(self.lru.lock().unwrap().get().map(|l| l.size()))
}
Expand Down Expand Up @@ -185,3 +189,27 @@ impl Storage for DiskCache {
.commit(f)?)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_disk_cache_type_name() {
let tempdir = tempfile::tempdir().unwrap();
let runtime = tokio::runtime::Builder::new_current_thread()
.build()
.unwrap();

let disk = DiskCache::new(
tempdir.path(),
1024 * 1024,
runtime.handle(),
PreprocessorCacheModeConfig::default(),
CacheMode::ReadWrite,
vec![],
);

assert_eq!(disk.cache_type_name(), "disk");
}
}
34 changes: 34 additions & 0 deletions src/cache/readonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ impl Storage for ReadOnlyStorage {
self.0.location()
}

/// Get the cache backend type name.
fn cache_type_name(&self) -> &'static str {
self.0.cache_type_name()
}

/// Get the current storage usage, if applicable.
async fn current_size(&self) -> Result<Option<u64>> {
self.0.current_size().await
Expand Down Expand Up @@ -188,4 +193,33 @@ mod test {
);
});
}

#[test]
fn readonly_storage_forwards_cache_type_name() {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.worker_threads(1)
.build()
.unwrap();

let tempdir = tempfile::Builder::new()
.prefix("readonly_cache_type_name")
.tempdir()
.expect("Failed to create tempdir");
let cache_dir = tempdir.path().join("cache");
std::fs::create_dir(&cache_dir).unwrap();

let disk_cache = crate::cache::disk::DiskCache::new(
&cache_dir,
1024 * 1024,
runtime.handle(),
super::PreprocessorCacheModeConfig::default(),
super::CacheMode::ReadWrite,
vec![],
);

let readonly_storage = ReadOnlyStorage(std::sync::Arc::new(disk_cache));

assert_eq!(readonly_storage.cache_type_name(), "disk");
}
}
40 changes: 22 additions & 18 deletions tests/integration/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ BACKENDS := redis redis-deprecated memcached memcached-deprecated s3 azblob webd
TOOLS := gcc clang cmake autotools coverage zstd

# Map backends to their compose profiles
PROFILE_autotools := autotools
PROFILE_azblob := azblob
PROFILE_basedirs := basedirs
PROFILE_clang := clang
PROFILE_cmake := cmake
PROFILE_coverage := coverage
PROFILE_gcc := gcc
PROFILE_memcached := memcached
PROFILE_memcached-deprecated := memcached
PROFILE_redis := redis
PROFILE_redis-deprecated := redis
PROFILE_s3 := s3
PROFILE_webdav := webdav
PROFILE_zstd := zstd
PROFILES_autotools := autotools
PROFILES_azblob := azblob
PROFILES_basedirs := basedirs redis memcached s3 azblob webdav
PROFILES_clang := clang
PROFILES_cmake := cmake
PROFILES_coverage := coverage
PROFILES_gcc := gcc
PROFILES_memcached := memcached
PROFILES_memcached-deprecated := memcached
PROFILES_redis := redis
PROFILES_redis-deprecated := redis
PROFILES_s3 := s3
PROFILES_webdav := webdav
PROFILES_zstd := zstd

# Map backends to their services
SERVICES_autotools :=
Expand Down Expand Up @@ -93,16 +93,20 @@ $(SCCACHE_BIN): $(PROJECT_ROOT)/Cargo.toml $(PROJECT_ROOT)/Cargo.lock
@echo "Binary built: $(SCCACHE_BIN)"
@ls -lh $(SCCACHE_BIN)

define profiles
$(foreach profile,$(PROFILES_$(1)),--profile $(profile))
endef

# Pattern rule for cleaning backends
clean-%:
@docker compose --profile $(PROFILE_$*) down -v
docker compose $(call profiles,$*) down -v

# Pattern rule for testing backends
test-%: build clean-%
@echo "Testing $* backend..."
@docker compose --profile $(PROFILE_$*) up --quiet-pull -d $(SERVICES_$*)
@docker compose --profile $(PROFILE_$*) run --quiet-pull --rm test-$*
@docker compose --profile $(PROFILE_$*) down
@docker compose $(call profiles,$*) up --quiet-pull -d $(SERVICES_$*)
@docker compose $(call profiles,$*) run --quiet-pull --rm test-$*
@docker compose $(call profiles,$*) down
@echo "$* test completed"

test-backends: $(addprefix test-,$(BACKENDS))
Expand Down
7 changes: 0 additions & 7 deletions tests/integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ services:
profiles:
- test
- redis
- basedirs

memcached:
image: memcached:latest
Expand All @@ -45,7 +44,6 @@ services:
profiles:
- test
- memcached
- basedirs

minio:
image: minio/minio:latest
Expand All @@ -62,7 +60,6 @@ services:
profiles:
- test
- s3
- basedirs

minio-setup:
image: minio/mc:latest
Expand All @@ -78,7 +75,6 @@ services:
profiles:
- test
- s3
- basedirs

azurite:
image: mcr.microsoft.com/azure-storage/azurite:latest
Expand All @@ -91,7 +87,6 @@ services:
profiles:
- test
- azblob
- basedirs

azurite-setup:
image: mcr.microsoft.com/azure-cli:latest
Expand All @@ -106,7 +101,6 @@ services:
profiles:
- test
- azblob
- basedirs

webdav:
image: hacdias/webdav:latest
Expand All @@ -119,7 +113,6 @@ services:
profiles:
- test
- webdav
- basedirs

test-redis-deprecated:
<<: *test-runner
Expand Down
Loading