gemini_rust/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
32 .get_cached_content(&self.name)
33 .await
34 .map_err(Box::new)
35 .context(ClientSnafu)
36 }
37
38 pub async fn update(&self, expiration: CacheExpirationRequest) -> Result<CachedContent, Error> {
40 self.client
41 .update_cached_content(&self.name, expiration)
42 .await
43 .map_err(Box::new)
44 .context(ClientSnafu)
45 }
46
47 pub async fn delete(self) -> Result<(), (Self, Error)> {
49 match self
50 .client
51 .delete_cached_content(&self.name)
52 .await
53 .map_err(Box::new)
54 .context(ClientSnafu)
55 {
56 Ok(response) => Ok(response),
57 Err(e) => Err((self, e)),
58 }
59 }
60}