refactor(cache): redesign cache system with structured keys and improved performance
- Add repo_path parameter to cached_response and cached_vec_response functions - Implement structured cache key format with namespace, repo_path, and request proto - Replace global cache with Moka in-memory cache using weight-based eviction - Set 256MB memory cap with 10-minute TTL and 2-minute TTI policy - Add metrics collection for cache operations and evictions - Implement efficient repo-scoped invalidation using key structure - Add detailed documentation comments explaining cache architecture - Remove outdated dependencies and update dependency versions - Add error handling for encoding failures in cache operations - Optimize Vec responses with length-delimited encoding and pre-allocation
This commit is contained in:
@@ -9,9 +9,16 @@ impl GitBare {
|
||||
return Ok(ObjectsSizeResponse::default());
|
||||
}
|
||||
|
||||
const MAX_OBJECTS_SIZE_OIDS: usize = 10_000;
|
||||
if request.oids.len() > MAX_OBJECTS_SIZE_OIDS {
|
||||
return Err(crate::error::GitError::InvalidArgument(format!(
|
||||
"too many oids (max {MAX_OBJECTS_SIZE_OIDS})"
|
||||
)));
|
||||
}
|
||||
|
||||
let mut input = String::new();
|
||||
for oid in &request.oids {
|
||||
crate::sanitize::validate_revision(oid)?;
|
||||
crate::sanitize::validate_oid_hex(oid)?;
|
||||
input.push_str(oid);
|
||||
input.push('\n');
|
||||
}
|
||||
@@ -49,6 +56,12 @@ impl GitBare {
|
||||
status_code: None,
|
||||
stderr: e.to_string(),
|
||||
})?;
|
||||
if !output.status.success() {
|
||||
return Err(crate::error::GitError::CommandFailed {
|
||||
status_code: output.status.code(),
|
||||
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let mut sizes = Vec::new();
|
||||
@@ -81,6 +94,12 @@ impl GitBare {
|
||||
status_code: None,
|
||||
stderr: e.to_string(),
|
||||
})?;
|
||||
if !output.status.success() {
|
||||
return Err(crate::error::GitError::CommandFailed {
|
||||
status_code: output.status.code(),
|
||||
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let size = stdout
|
||||
|
||||
Reference in New Issue
Block a user