Skip to content

Commit

Permalink
feat: allow invalidating list_keys cache (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
willothy authored Oct 5, 2024
1 parent b0bf28c commit 9cf56ea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/models/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub struct ListKeysRequest {

/// The pagination cursor indicating the last key that was returned.
pub cursor: Option<String>,

/// Whether to revalidate the cache for this request.
pub revalidate_cache: Option<bool>,
}

impl ListKeysRequest {
Expand All @@ -37,6 +40,7 @@ impl ListKeysRequest {
/// assert_eq!(r.limit, None);
/// assert_eq!(r.cursor, None);
/// assert_eq!(r.owner_id, None);
/// assert_eq!(r.revalidate_cache, None);
/// ```
#[must_use]
pub fn new<T: Into<String>>(api_id: T) -> Self {
Expand All @@ -45,6 +49,7 @@ impl ListKeysRequest {
owner_id: None,
limit: None,
cursor: None,
revalidate_cache: None,
}
}

Expand Down Expand Up @@ -110,6 +115,26 @@ impl ListKeysRequest {
self.owner_id = Some(owner_id.into());
self
}

/// Sets the flag for revalidating the cache for this request.
///
/// # Arguments
/// - `revalidate_cache`: Whether to revalidate the cache with this request.
///
/// # Returns
/// Self for chained calls.
///
/// # Example
/// ```
/// # use unkey::models::ListKeysRequest;
/// let r = ListKeysRequest::new("test").set_revalidate_cache(true);
///
/// assert_eq!(r.revalidate_cache.unwrap(), true);
/// ```
pub fn set_revalidate_cache(mut self, revalidate_cache: bool) -> Self {
self.revalidate_cache = Some(revalidate_cache);
self
}
}

/// An incoming paginated list keys response.
Expand Down
4 changes: 4 additions & 0 deletions src/services/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ impl ApiService {
.query_insert("apiId", &req.api_id)
.query_insert("limit", &req.limit.unwrap_or(100).to_string());

if let Some(revalidate) = &req.revalidate_cache {
route.query_insert("revalidateKeysCache", &revalidate.to_string());
}

if let Some(owner) = &req.owner_id {
route.query_insert("ownerId", owner);
}
Expand Down

0 comments on commit 9cf56ea

Please sign in to comment.