expire

package
v0.0.0-...-b14404a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

package expire optimally wait for the next deadline when there are at least n number of items to expire.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option struct {
	Threshold int           // How many expired keys to keep before cleaning.
	Expiry    time.Duration // How long before a key expires (it must be the same for all).
	Interval  time.Duration // The time window to accumulate the keys.
}

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue(opt QueueOption) *Queue

func (*Queue) Add

func (q *Queue) Add(ctx context.Context, deadline time.Time)

func (*Queue) Stop

func (q *Queue) Stop()

type QueueOption

type QueueOption struct {
	Window  time.Duration
	Handler func()
}

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

func New

func New(opt Option) *Worker

func (*Worker) Add

func (w *Worker) Add(ctx context.Context, n int)

Add adds n number of keys to expire.

func (*Worker) HandleFunc

func (w *Worker) HandleFunc(ctx context.Context, h func(ctx context.Context) error) func()

HandleFunc executes a background job that handles the execution of the handler when the deadline is exceeded.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL