-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement negative cache API endpoint
- Loading branch information
Showing
11 changed files
with
129 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
mod builder; | ||
mod duplicator; | ||
mod processor; | ||
mod load_balancer; | ||
mod model; | ||
mod negative_cache; | ||
mod queue; | ||
|
||
pub use builder::Builder; | ||
pub use duplicator::Enqueuer; | ||
pub use processor::Enqueuer; | ||
pub use model::Payload; | ||
pub use queue::Priority; | ||
pub use negative_cache::NegativeCache; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
use std::collections::HashSet; | ||
use std::sync::Arc; | ||
|
||
use tokio::sync::RwLock; | ||
|
||
pub(super) struct NegativeCache { | ||
struct Inner { | ||
cache: RwLock<HashSet<String>>, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct NegativeCache { | ||
inner: Arc<Inner>, | ||
} | ||
|
||
impl NegativeCache { | ||
pub(super) fn new() -> Self { | ||
NegativeCache { cache: RwLock::new(HashSet::new()) } | ||
NegativeCache { | ||
inner: Arc::new(Inner { | ||
cache: RwLock::new(HashSet::new()), | ||
}), | ||
} | ||
} | ||
|
||
pub(super) async fn ban(&self, url: &str) { | ||
self.cache.write().await.insert(url.to_owned()); | ||
self.inner.cache.write().await.insert(url.to_owned()); | ||
} | ||
|
||
pub(super) async fn is_banned(&self, url: &str) -> bool { | ||
self.cache.read().await.contains(url) | ||
self.inner.cache.read().await.contains(url) | ||
} | ||
|
||
pub async fn list(&self) -> Vec<String> { | ||
Vec::from_iter(self.inner.cache.read().await.iter().map(|s| s.to_owned())) | ||
} | ||
|
||
pub async fn delete(&self, url: &str) { | ||
self.inner.cache.write().await.remove(url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
mod queue; | ||
mod two_level_queue; | ||
mod priority; | ||
mod simple; | ||
|
||
pub use two_level_queue::{ | ||
two_level_queue, Priority, Priorized, TwoLevelQueueReceiver, TwoLevelQueueSender, | ||
}; | ||
pub use priority::{priority_queue, Priority, Priorized, PriorizedReceiver, PriorizedSender}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.