runtime: add cache backend factory seam
This commit is contained in:
@@ -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 не изменено
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user