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