Documentation
¶
Index ¶
- Constants
- Variables
- type Gate
- func (g *Gate) Commit(ctx context.Context, cacheKey string, commit func() error) error
- func (g *Gate) GuardDeletion(ctx context.Context, cacheKey string, remove func()) error
- func (g *Gate) HoldRead(ctx context.Context, cacheKey string) (func(), error)
- func (g *Gate) HoldUpload(ctx context.Context, uploadID string) (func(), error)
- func (g *Gate) Open(ctx context.Context, cacheKey string, ...) (*OpenedCacheEntry, error)
- func (g *Gate) TryHoldDeletion(cacheKey string) (func(), bool)
- func (g *Gate) TryHoldRead(cacheKey string) (func(), bool)
- func (g *Gate) TryHoldUpload(uploadID string) (func(), bool)
- type OpenedCacheEntry
- type Store
- type Tracker
- func (t *Tracker) FlushWhileGuarded(ctx context.Context, contentID int64) error
- func (t *Tracker) Forget(contentID int64)
- func (t *Tracker) Latest(contentID int64) time.Time
- func (t *Tracker) RecordAccess(ctx context.Context, contentID int64, durableAccess *time.Time) error
- func (t *Tracker) RecordCommit(ctx context.Context, contentID int64, durableAccess *time.Time) error
- func (t *Tracker) Run(ctx context.Context, gate *Gate, logger *slog.Logger)
- func (t *Tracker) SafeForLRU() bool
Constants ¶
const ( // DefaultPersistenceInterval bounds foreground cache-access writes while // keeping the durable LRU order reasonably current across restarts. DefaultPersistenceInterval = time.Minute )
const ( // DeletionWaitLimit bounds exclusive cache permit acquisition. DeletionWaitLimit = 30 * time.Second )
Variables ¶
var ErrDeletionBusy = errors.New("cache deletion permit wait limit exceeded")
ErrDeletionBusy reports that the deletion permit wait limit expired.
var ErrLRUAccessUncertain = errors.New("cache access is not reliable enough for LRU eviction")
ErrLRUAccessUncertain means an access timestamp could not be retained or persisted. LRU eviction must remain paused for the rest of the process.
Functions ¶
This section is empty.
Types ¶
type Gate ¶
type Gate struct {
// contains filtered or unexported fields
}
Gate serializes cache opens and commits with physical deletion for the same content cache key. Idle entries are removed as soon as their last user exits.
func (*Gate) GuardDeletion ¶
GuardDeletion waits for open bodies and serializes final checks and physical deletion for one cache key.
func (*Gate) HoldRead ¶
HoldRead protects a cache entry from deletion across multiple opens. The returned release function is idempotent and must be called by the holder.
func (*Gate) HoldUpload ¶ added in v0.1.1
HoldUpload serializes publication and completion of one multipart upload.
func (*Gate) Open ¶
func (g *Gate) Open( ctx context.Context, cacheKey string, open func() (io.ReadCloser, *cache.ObjectInfo, error), ) (*OpenedCacheEntry, error)
Open protects a successful cache open until the returned body is closed.
func (*Gate) TryHoldDeletion ¶ added in v0.1.1
TryHoldDeletion acquires exclusive access without delaying active readers.
func (*Gate) TryHoldRead ¶ added in v0.1.1
TryHoldRead acquires a read permit without queuing behind deletion.
func (*Gate) TryHoldUpload ¶ added in v0.1.1
TryHoldUpload skips a multipart upload that is being changed by a request.
type OpenedCacheEntry ¶
type OpenedCacheEntry struct {
Body io.ReadCloser
Info *cache.ObjectInfo
}
OpenedCacheEntry keeps a cache entry protected from deletion until Body is closed.
type Store ¶
type Store interface {
RecordContentCacheAccess(context.Context, int64, time.Time) error
RecordContentCacheCommit(context.Context, int64, time.Time) error
}
Store persists foreground cache access and cache commit metadata. Store persists cache recency. The unit is the content payload, because one cache file backs every version that shares those bytes.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker coalesces durable access-time writes and retains the latest exact in-process access used by LRU finalization.
func NewTracker ¶
NewTracker creates a bounded foreground cache-access tracker.
func (*Tracker) FlushWhileGuarded ¶
FlushWhileGuarded persists one version's latest access. The caller must hold the version's cache gate.
func (*Tracker) Forget ¶
Forget removes tracking state after the cache entry is deleted or its version is permanently removed.
func (*Tracker) RecordAccess ¶
func (t *Tracker) RecordAccess( ctx context.Context, contentID int64, durableAccess *time.Time, ) error
RecordAccess records one successful foreground cache open.
func (*Tracker) RecordCommit ¶
func (t *Tracker) RecordCommit( ctx context.Context, contentID int64, durableAccess *time.Time, ) error
RecordCommit records a successful local cache commit and forces the presence and access metadata write.
func (*Tracker) SafeForLRU ¶
SafeForLRU reports whether all access timestamps that could affect LRU deletion are still represented in memory or durable storage.