singleflight

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package singleflight holds the compute locks behind CACHE.GET: when a cached key is missing, only one client gets to recompute it while the others wait for the key to be written.

A compute lock is cleared by any write event on its key (db listener), by CACHE.RELEASE, or when it expires.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

func New

func New(db *store.DB) *Group

func (*Group) Acquire

func (g *Group) Acquire(key string, owner int64, ttl time.Duration) bool

Acquire takes the compute lock of key for ttl unless a live one exists.

func (*Group) Len

func (g *Group) Len() int

Len returns the number of compute locks (including expired ones not yet removed).

func (*Group) Locked

func (g *Group) Locked(key string) bool

Locked reports whether key has a live compute lock.

func (*Group) Release

func (g *Group) Release(key string) bool

Release clears the compute lock of key. Returns true if a live one existed.

Jump to

Keyboard shortcuts

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