Skip to content

Commit b969d15

Browse files
densumeshcdxker
authored andcommitted
feature: req-reply cache for get tool function params
1 parent 6e566a2 commit b969d15

3 files changed

Lines changed: 182 additions & 15 deletions

File tree

server/Cargo.lock

Lines changed: 171 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ utoipa-swagger-ui = { version = "7.0.1", features = ["actix-web"] }
171171
bb8-redis = "0.15.0"
172172
signal-hook = "0.3.17"
173173
blake3 = "1.5.1"
174-
actix-http = "3.7.0"
174+
actix-http = "3.10.0"
175175
clickhouse = { version = "0.12.0", features = ["time", "uuid"] }
176176
prometheus = "0.13.4"
177177
chm = "0.1.16"
@@ -192,6 +192,7 @@ bytes = "1.9.0"
192192
pagefind = { version = "1.3.0" }
193193
tl = "0.7.8"
194194
url = "2.5.4"
195+
actix-request-reply-cache = "0.1.6"
195196

196197
[build-dependencies]
197198
dotenvy = "0.15.7"

server/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
};
1616
use actix_cors::Cors;
1717
use actix_identity::IdentityMiddleware;
18+
use actix_request_reply_cache::RedisCacheMiddlewareBuilder;
1819
use actix_session::{config::PersistentSession, storage::RedisSessionStore, SessionMiddleware};
1920
use actix_web::{
2021
cookie::{Key, SameSite},
@@ -1101,6 +1102,14 @@ pub fn main() -> std::io::Result<()> {
11011102
.service(
11021103
web::resource("/message/get_tool_function_params")
11031104
.route(web::post().to(handlers::message_handler::get_tool_function_params))
1105+
.wrap(RedisCacheMiddlewareBuilder::new(redis_url)
1106+
.cache_prefix("function_params:")
1107+
.ttl(60 * 60 * 24)
1108+
.cache_if(|ctx| {
1109+
return ctx.body.get("audio_input").is_none() || ctx.body.get("audio_input").unwrap().is_null();
1110+
})
1111+
.build()
1112+
)
11041113
)
11051114
.service(
11061115
web::resource("/message/{message_id}")

0 commit comments

Comments
 (0)