mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-10-10 04:53:09 +08:00
56064d1981
- Share one admitted lifecycle policy between regular and archive links. - Reject and release links that combine TTL caching with owned resources. - Keep wrapper clones independent from the source cache expiration. - Cover reuse, reference, invalidation, conflict, and clone behavior. Co-authored-by: nostalume <nostalucent@gmail.com> Co-authored-by: Codex <267193182+codex@users.noreply.github.com>
35 lines
888 B
Go
35 lines
888 B
Go
package op
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
|
)
|
|
|
|
var errConflictingLinkLifecycle = errors.New("invalid link lifecycle: expiration cannot be combined with owned closers or RequireReference")
|
|
|
|
type linkCachePolicy struct {
|
|
expiration *time.Duration
|
|
requireReference bool
|
|
}
|
|
|
|
func admitLink(link *model.Link, obj model.Obj) (*objWithLink, error) {
|
|
if link.Expiration != nil && (link.RequireReference || link.SyncClosers.Length() > 0) {
|
|
return nil, errors.Join(errConflictingLinkLifecycle, link.Close())
|
|
}
|
|
return &objWithLink{
|
|
link: link,
|
|
obj: obj,
|
|
policy: linkCachePolicy{
|
|
expiration: link.Expiration,
|
|
requireReference: link.RequireReference,
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
func (ol *objWithLink) acquire() bool {
|
|
return ol.policy.expiration != nil ||
|
|
ol.link.SyncClosers.AcquireReference() || !ol.policy.requireReference
|
|
}
|