adk_gemini/cache/
handle.rs1use snafu::ResultExt;
2use std::sync::Arc;
3
4use super::model::*;
5use super::*;
6use crate::client::GeminiClient;
7
8pub struct CachedContentHandle {
13 pub name: String,
15 client: Arc<GeminiClient>,
16}
17
18impl CachedContentHandle {
19 pub(crate) fn new(name: String, client: Arc<GeminiClient>) -> Self {
21 Self { name, client }
22 }
23
24 pub fn name(&self) -> &str {
26 &self.name
27 }
28
29 pub async fn get(&self) -> Result<CachedContent, Error> {
31 self.client.get_cached_content(&self.name).await.map_err(Box::new).context(ClientSnafu)
32 }
33
34 pub async fn update(&self, expiration: CacheExpirationRequest) -> Result<CachedContent, Error> {
36 self.client
37 .update_cached_content(&self.name, expiration)
38 .await
39 .map_err(Box::new)
40 .context(ClientSnafu)
41 }
42
43 pub async fn delete(self) -> Result<(), (Self, Error)> {
45 match self
46 .client
47 .delete_cached_content(&self.name)
48 .await
49 .map_err(Box::new)
50 .context(ClientSnafu)
51 {
52 Ok(response) => Ok(response),
53 Err(e) => Err((self, e)),
54 }
55 }
56}