Skip to content

an implementation of the XFetch probabilistic early expiration algorithm in Go

Notifications You must be signed in to change notification settings

YutaMiyake/xfetchgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

xfetchgo

xfetchgo implements the XFetch algorithm of Optimal Probabilistic Cache Stampede Prevention (2015) by Vattani, Chierichetti, and Lowenstein. The XFetch is for efficient cache management in parallel computing environments. It helps prevent cache stampedes and optimizes cache recomputation without the need for coordination between processes.

Installation

go get github.com/YutaMiyake/xfetchgo

Usage

Creating a new cache entry:

cacheEntry := xfetch.NewCacheEntry(
    func() string {
        // Your expensive computation here 
        return "cached value"
    }, 
    xfetch.WithTTL(5 * time.Minute), 
    xfetch.WithDelta(100 * time.Millisecond), 
    xfetch.WithBeta(1.5),
)

Checking if the cache is expired and recomputing if necessary:

if cacheEntry.IsExpired() { 
    // Recompute the cache
} else {
    value := cacheEntry.Get() 
    // Use the cached value
}

License

MIT License

About

an implementation of the XFetch probabilistic early expiration algorithm in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages