cache2goGo 缓存库
cache2go 是一个 Go 的并发安全缓存库,具有到期和访问计数器的功能。
示例代码:
package main import ( "github.com/muesli/cache2go" "fmt" "time" ) // Keys & values in cache2go can be off arbitrary types, e.g. a struct. type myStruct struct { text string moreData []byte } func main() { // Accessing a new cache table for the first time will create it. cache := cache2go.Cache("myCache") // We will put a new item in the cache. It will expire after // not being accessed via Value(key) for more than 5 seconds. val := myStruct{"This is a test!", []byte{}} cache.Add("someKey", 5*time.Second, &val) // Let's retrieve the item from the cache. res, err := cache.Value("someKey") if err == nil { fmt.Println("Found value in cache:", res.Data().(*myStruct).text) } else { fmt.Println("Error retrieving value from cache:", err) } // Wait for the item to expire in cache. time.Sleep(6 * time.Second) res, err = cache.Value("someKey") if err != nil { fmt.Println("Item is not cached (anymore).") } // Add another item that never expires. cache.Add("someKey", 0, &val) // cache2go supports a few handy callbacks and loading mechanisms. cache.SetAboutToDeleteItemCallback(func(e *cache2go.CacheItem) { fmt.Println("Deleting:", e.Key(), e.Data().(*myStruct).text, e.CreatedOn()) }) // Remove the item from the cache. cache.Delete("someKey") // And wipe the entire cache table. cache.Flush() }
go run mycachedapp.go
评论
supycachePython 缓存库
supycache是Python对缓存的简单封装库,支持包括内存缓存、memcached和redis。示例代码:import timeimport supycache@supycache.supyca
supycachePython 缓存库
0
LRUCacheGo 缓存库
用Go编写的一个简单的LRUCache库,示例代码:// define a type that can be used with the cachetype myCacheableValue stru
LRUCacheGo 缓存库
0
qUIptJavaScript缓存库
qUIpt是一個很小很小的JavaScriptLibrary,所有原始碼也才只有115行而已(包括註解),我覺得作者MarioHeiderich真是太有創意了,他的原理十分簡單,使用的Cache方法是
qUIptJavaScript缓存库
0
phpFastCachePHP 缓存库
phpFastCache是一个开源的PHP缓存库,只提供一个简单的PHP文件,可方便集成到已有项目,支持多种缓存方法,包括:apc,memcache,memcached,wincache,files,
phpFastCachePHP 缓存库
0
GDRSImageCacheiOS 图片缓存库
GDRSImageCache是iOS一个非常小型的图片缓存和更改图片大小的开发包。给定一个URL后该库会通过后台线程获取图片并在内存中缓存。使用方法:UIImageView *anImageView
GDRSImageCacheiOS 图片缓存库
0