GroupCache -


Apache
Windows
Google Go

软件简介

groupcache 是一个缓存和缓存填充库,旨在很多情况下替换
memcached

示例代码:

me := "http://10.0.0.1"
peers := groupcache.NewHTTPPool(me)

// Whenever peers change:
peers.Set("http://10.0.0.1", "http://10.0.0.2", "http://10.0.0.3")

var thumbNails = groupcache.NewGroup("thumbnail", 64<<20, groupcache.GetterFunc(
    func(ctx groupcache.Context, key string, dest groupcache.Sink) error {
        fileName := key
        dest.SetBytes(generateThumbnail(fileName))
        return nil
    }))

var data []byte
err := thumbNails.Get(ctx, "big-file.jpg",
    groupcache.AllocatingByteSliceSink(&data))
// ...
http.ServeContent(w, r, "big-file-thumb.jpg", modTime, bytes.NewReader(data))

这里有个介绍的幻灯片(需FQ):http://talks.golang.org/2013/oscon-dl.slide