🐛 Fix cache issue

This commit is contained in:
2024-12-29 01:03:22 +08:00
parent b041ce3e06
commit e89f149336
6 changed files with 28 additions and 14 deletions

View File

@ -1,11 +1,18 @@
package models
import (
"context"
"fmt"
"time"
"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
"github.com/eko/gocache/lib/v4/cache"
"github.com/eko/gocache/lib/v4/marshaler"
localCache "git.solsynth.dev/hypernet/paperclip/pkg/internal/cache"
"gorm.io/datatypes"
"gorm.io/gorm"
)
const (
@ -70,6 +77,19 @@ type Attachment struct {
IsMature bool `json:"is_mature" gorm:"-"`
}
func (v *Attachment) AfterUpdate(tx *gorm.DB) error {
cacheManager := cache.New[any](localCache.S)
marshal := marshaler.New(cacheManager)
ctx := context.Background()
_ = marshal.Delete(
ctx,
fmt.Sprintf("attachment#%s", v.Rid),
)
return nil
}
// Data model for in progress multipart attachments
type AttachmentFragment struct {
cruda.BaseModel