Skip to content

Commit fe71498

Browse files
zk-stevethuan2172001
authored andcommitted
temp
1 parent d2fe57a commit fe71498

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,17 @@ Hierarchical child config via env, separated by using `__`. Specify list values
102102
| SERVER\_\_PORT | | |
103103
| SERVICE_NAME | | |
104104
| EXPORTER_ENDPOINT | | |
105-
| DB\_\_PG\_\_URL | | |
106-
| DB\_\_PG\_\_MAX_SIZE | | |
107-
| REDIS\_\_HOST | | |
108-
| REDIS\_\_PORT | | |
105+
| DB\_\_PG\_\_URL | "LOCALHOST" | |
106+
| DB\_\_PG\_\_MAX_SIZE | "5432" | |
107+
| REDIS\_\_HOST | "LOCALHOST" | |
108+
| REDIS\_\_PORT | "6379" | |
109109

110110
Make sure to set these environment variables according to your needs before running the server.
111111

112112
## GitHub Flow CI Configuration
113113

114114
1. **Set Docker Hub Secrets:**
115+
115116
- Go to repository Settings > Secrets.
116117
- Add `DOCKER_USERNAME` and `DOCKERHUB_TOKEN`.
117118

src/adapter/src/repositories/in_memory/cache.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ pub struct InMemoryCache {
1515
cache: Arc<RwLock<HashMap<String, (String, Option<SystemTime>)>>>,
1616
}
1717

18+
impl Default for InMemoryCache {
19+
/// Creates a new default instance of in-memory cache.
20+
fn default() -> Self {
21+
Self {
22+
cache: Arc::new(RwLock::default()),
23+
}
24+
}
25+
}
26+
1827
impl InMemoryCache {
1928
/// Removes expired entries from the cache asynchronously.
2029
///
@@ -34,15 +43,6 @@ impl InMemoryCache {
3443
}
3544
}
3645

37-
impl Default for InMemoryCache {
38-
/// Creates a new default instance of in-memory cache.
39-
fn default() -> Self {
40-
Self {
41-
cache: Arc::new(RwLock::new(HashMap::new())),
42-
}
43-
}
44-
}
45-
4646
#[async_trait]
4747
impl CachePort for InMemoryCache {
4848
/// Retrieves a value from the cache based on the provided key.
@@ -89,8 +89,10 @@ impl CachePort for InMemoryCache {
8989
// Calculate expiry_time based on expiration duration
9090
let expiry_time = expiration.map(|exp| SystemTime::now() + exp);
9191

92-
let mut cache = self.cache.write().await;
93-
cache.insert(key.to_string(), (value.to_string(), expiry_time));
92+
self.cache
93+
.write()
94+
.await
95+
.insert(key.to_string(), (value.to_string(), expiry_time));
9496
Ok(())
9597
}
9698

@@ -104,11 +106,11 @@ impl CachePort for InMemoryCache {
104106
///
105107
/// Returns `Ok(())` if the key is found and removed, otherwise returns a `CoreError`.
106108
async fn del(&mut self, key: &str) -> Result<(), CoreError> {
107-
let mut cache = self.cache.write().await;
108-
if cache.remove(key).is_some() {
109-
Ok(())
110-
} else {
111-
Err(CoreError::NotFound)
112-
}
109+
self.cache
110+
.write()
111+
.await
112+
.remove(key)
113+
.map(|_| ())
114+
.ok_or(CoreError::NotFound)
113115
}
114116
}

src/adapter/src/repositories/redis/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl CachePort for RedisCache {
6161
///
6262
/// # Returns
6363
///
64-
/// Returns a `Result` indicating success (`true`) or failure (`false`).
64+
/// Returns a `Result` where `Ok(())` indicates success (key was set) and `Err(CoreError)` indicates failure.
6565
async fn set(
6666
&mut self,
6767
key: &str,

src/core/src/ports/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub trait CachePort {
2828
///
2929
/// # Returns
3030
///
31-
/// Returns `true` if the key-value pair is successfully set in the cache, `false` otherwise.
31+
/// Returns `Result(())` if the key-value pair is successfully set in the cache, `false` otherwise.
3232
async fn set(
3333
&mut self,
3434
key: &str,
@@ -44,6 +44,6 @@ pub trait CachePort {
4444
///
4545
/// # Returns
4646
///
47-
/// Returns `true` if the key-value pair is successfully removed from the cache, `false` otherwise.
47+
/// Returns `Result(())` if the key-value pair is successfully removed from the cache, `false` otherwise.
4848
async fn del(&mut self, key: &str) -> Result<(), CoreError>;
4949
}

0 commit comments

Comments
 (0)