feat(posts): invalidate caches on write operations
This commit is contained in:
parent
887aacb5f1
commit
91caf3f8bd
@ -344,6 +344,14 @@ pub async fn create_post(
|
||||
|
||||
tx.commit().await.map_err(tx_error)?;
|
||||
|
||||
// Invalidate caches after successful creation
|
||||
#[cfg(feature = "server")]
|
||||
{
|
||||
cache::invalidate_post_lists();
|
||||
cache::invalidate_all_tags();
|
||||
cache::invalidate_post_stats();
|
||||
}
|
||||
|
||||
Ok(CreatePostResponse {
|
||||
success: true,
|
||||
message: "创建成功".to_string(),
|
||||
@ -516,6 +524,20 @@ pub async fn update_post(
|
||||
|
||||
tx.commit().await.map_err(tx_error)?;
|
||||
|
||||
// Invalidate caches after successful update
|
||||
#[cfg(feature = "server")]
|
||||
{
|
||||
cache::invalidate_post_lists();
|
||||
cache::invalidate_all_tags();
|
||||
cache::invalidate_post_by_slug(&final_slug).await;
|
||||
cache::invalidate_post_stats();
|
||||
|
||||
// Invalidate tag-specific caches for new tags
|
||||
for tag_name in &tags_cleaned {
|
||||
cache::invalidate_posts_by_tag(tag_name).await;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(CreatePostResponse {
|
||||
success: true,
|
||||
message: "更新成功".to_string(),
|
||||
@ -705,6 +727,12 @@ pub async fn delete_post(post_id: i32) -> Result<CreatePostResponse, ServerFnErr
|
||||
});
|
||||
}
|
||||
|
||||
// Invalidate all post-related caches
|
||||
#[cfg(feature = "server")]
|
||||
{
|
||||
cache::invalidate_all_post_caches();
|
||||
}
|
||||
|
||||
Ok(CreatePostResponse {
|
||||
success: true,
|
||||
message: "删除成功".to_string(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user