runtime: add cache backend factory seam

This commit is contained in:
github-ops
2026-05-15 13:12:38 +00:00
parent ad61350c2e
commit 280ea99628
3 changed files with 52 additions and 0 deletions
+1
View File
@@ -168,4 +168,5 @@ Progress:
- Phase 3 dependency slice: added public tenancy seam in `crank-core``TenantId`, `TenantResolutionContext`, `TenantController`, `TenancyError`, and `SingleTenantController` — so `cloud` can build hosted tenant routing without bypassing the shared extension model
- Phase 3 dependency slice: added public metering seam in `crank-core``MeteringEvent`, `MeteringSink`, `SharedMeteringSink`, and `NoopMeteringSink` — so `cloud` can add hosted usage capture without introducing private-only contracts
- Phase 3 dependency slice: added public billing seam in `crank-core``BillingHook`, `BillingGate`, `BillingError`, `SharedBillingHook`, and `NoopBillingHook` — so `cloud` can layer billing policy without private-only contracts in the base repo
- Phase 3 dependency slice: added `CacheBackendFactory` in `crank-runtime` with `BuiltinCacheBackendFactory`; unlike the original draft, the seam lives in runtime rather than core to avoid a `crank-core -> crank-runtime` dependency cycle around `RuntimeCacheStores`
- backward-compatible alias `CommunityMachineCredentialVerifier` сохранен, поведение Community не изменено
+47
View File
@@ -0,0 +1,47 @@
use std::sync::Arc;
use async_trait::async_trait;
use crate::{
RuntimeCacheConfig, RuntimeCacheStoreInitError, RuntimeCacheStores,
};
#[async_trait]
pub trait CacheBackendFactory: Send + Sync {
async fn build(
&self,
config: &RuntimeCacheConfig,
) -> Result<RuntimeCacheStores, RuntimeCacheStoreInitError>;
}
pub type SharedCacheBackendFactory = Arc<dyn CacheBackendFactory>;
#[derive(Clone, Copy, Debug, Default)]
pub struct BuiltinCacheBackendFactory;
#[async_trait]
impl CacheBackendFactory for BuiltinCacheBackendFactory {
async fn build(
&self,
config: &RuntimeCacheConfig,
) -> Result<RuntimeCacheStores, RuntimeCacheStoreInitError> {
RuntimeCacheStores::from_config(config).await
}
}
#[cfg(test)]
mod tests {
use crate::{CacheBackendFactory, RuntimeCacheConfig};
use super::BuiltinCacheBackendFactory;
#[tokio::test]
async fn builtin_factory_builds_default_memory_stores() {
let stores = BuiltinCacheBackendFactory
.build(&RuntimeCacheConfig::default())
.await
.unwrap();
assert_eq!(stores.backend, crank_core::CacheBackend::Memory);
}
}
+4
View File
@@ -1,6 +1,7 @@
mod aggregation;
mod auth;
mod cache;
mod cache_factory;
mod error;
mod executor;
mod executor_builder;
@@ -18,6 +19,9 @@ pub use cache::{
InMemoryResponseCacheStore, RedisCacheStore, RuntimeCacheConfig, RuntimeCacheConfigError,
RuntimeCacheStoreInitError, RuntimeCacheStores,
};
pub use cache_factory::{
BuiltinCacheBackendFactory, CacheBackendFactory, SharedCacheBackendFactory,
};
pub use error::RuntimeError;
pub use executor::RuntimeExecutor;
pub use executor_builder::{RuntimeExecutorBuilder, community_default};