some strange storage stuff
This commit is contained in:
@@ -157,6 +157,20 @@ func (p *GrainLocalPool) Purge() {
|
||||
}
|
||||
}
|
||||
|
||||
// RefreshExpiry resets the expiry timestamp for a living grain to now + TTL.
|
||||
// Called after successful mutations to implement a sliding inactivity window.
|
||||
func (p *GrainLocalPool) RefreshExpiry(id CartId) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
for i := range p.expiry {
|
||||
g := p.expiry[i].Grain
|
||||
if g != nil && g.Id == id {
|
||||
p.expiry[i].Expires = time.Now().Add(p.Ttl)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetGrains returns a legacy view of grains (copy) for compatibility.
|
||||
func (p *GrainLocalPool) GetGrains() map[CartId]*CartGrain {
|
||||
p.mu.RLock()
|
||||
@@ -225,7 +239,12 @@ func (p *GrainLocalPool) Apply(id CartId, mutation interface{}) (*CartGrain, err
|
||||
if err != nil || grain == nil {
|
||||
return nil, err
|
||||
}
|
||||
return grain.Apply(mutation, false)
|
||||
result, applyErr := grain.Apply(mutation, false)
|
||||
// Sliding TTL: refresh expiry on successful non-replay mutation (Apply always non-replay here)
|
||||
if applyErr == nil && result != nil {
|
||||
p.RefreshExpiry(id)
|
||||
}
|
||||
return result, applyErr
|
||||
}
|
||||
|
||||
// Get returns current state (legacy wrapper).
|
||||
|
||||
Reference in New Issue
Block a user