Skip to content

Commit 504edcd

Browse files
committed
(caching) Improve storage cache cleanup, do not clean very fresh files
We should not clean very fresh files, even we are short on disk space. Also update README and add testpoint for token test Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 60878e2 commit 504edcd

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ JWT secret is configured in the `config.toml` file.
4545
```
4646
This will generate a JWT token for the user.
4747

48+
#### Testing Token Validity
49+
50+
You can verify if a token is valid using the `/v1/checkauth` endpoint:
51+
52+
```bash
53+
curl -X GET http://localhost:3000/v1/checkauth \
54+
-H "Authorization: Bearer <JWT_TOKEN>"
55+
```
56+
57+
**Responses:**
58+
- `200 OK` with body `Authorized: user@email.com` - Token is valid
59+
- `401 Unauthorized` with body `Unauthorized` - Token is invalid or missing
60+
4861
### Testing upload and download using curl
4962

5063
```bash

src/storcaching.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ async fn clean_disk(cache_dir: String) {
8989
oldest_file = file;
9090
}
9191
}
92-
delete_cache_file(oldest_file.file);
92+
// if file is less than 60 min old, do not delete it
93+
if oldest_file.last_update.elapsed().unwrap() > Duration::from_secs(60 * 60) {
94+
delete_cache_file(oldest_file.file);
95+
} else {
96+
println!("File is less than 60 min old, skipping: {}, sleeping 60 seconds", oldest_file.file);
97+
// sleep 60 seconds
98+
tokio::time::sleep(Duration::from_secs(60)).await;
99+
}
93100
}
94101

95102
/// Cache housekeeping loop

0 commit comments

Comments
 (0)