pub struct ExpirationService {
index: Arc<dyn IndexBackend + Send + Sync>,
config: ExpirationConfig,
}Expand description
Service for garbage collecting memories that have exceeded their TTL.
Unlike RetentionGarbageCollector which uses retention policies based on age,
this service checks the explicit expires_at timestamp set at capture time.
§Thread Safety
The service holds an Arc reference to the index backend,
making it safe to share across threads.
Fields§
§index: Arc<dyn IndexBackend + Send + Sync>Reference to the index backend for querying and updating memories.
config: ExpirationConfigExpiration configuration.
Implementations§
Source§impl ExpirationService
impl ExpirationService
Sourcepub fn new(
index: Arc<dyn IndexBackend + Send + Sync>,
config: ExpirationConfig,
) -> Self
pub fn new( index: Arc<dyn IndexBackend + Send + Sync>, config: ExpirationConfig, ) -> Self
Creates a new expiration service.
§Arguments
index- Shared reference to the index backend.config- Expiration configuration.
Sourcepub fn should_run_cleanup(&self) -> bool
pub fn should_run_cleanup(&self) -> bool
Determines whether cleanup should run based on configured probability.
Uses a random number generator to decide probabilistically. This enables lazy, opportunistic cleanup without expensive full scans on every operation.
§Returns
true if cleanup should run, false otherwise.
Sourcepub fn gc_expired_memories(&self, dry_run: bool) -> Result<ExpirationGcResult>
pub fn gc_expired_memories(&self, dry_run: bool) -> Result<ExpirationGcResult>
Performs garbage collection on TTL-expired memories.
This method:
- Lists all active (non-tombstoned) memories
- Checks each memory for TTL expiration (
expires_at < now) - Tombstones expired memories (unless
dry_run)
§Arguments
dry_run- If true, only report what would be done without making changes
§Returns
An ExpirationGcResult containing statistics about the operation.
§Errors
Returns an error if index backend operations fail.
Sourcepub const fn config(&self) -> &ExpirationConfig
pub const fn config(&self) -> &ExpirationConfig
Returns the current expiration configuration.
Auto Trait Implementations§
impl Freeze for ExpirationService
impl !RefUnwindSafe for ExpirationService
impl Send for ExpirationService
impl Sync for ExpirationService
impl Unpin for ExpirationService
impl !UnwindSafe for ExpirationService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].