Go 缓存库 cache2go

码农软件 · 软件分类 · 缓存系统 · 2019-08-29 18:27:23

软件介绍

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

本文地址:https://codercto.com/soft/d/13446.html

Python带我起飞

Python带我起飞

李金洪 / 电子工业出版社 / 2018-6 / 79

《Python带我起飞——入门、进阶、商业实战》针对Python 3.5 以上版本,采用“理论+实践”的形式编写,通过大量的实例(共42 个),全面而深入地讲解“Python 基础语法”和“Python 项目应用”两方面内容。书中的实例具有很强的实用性,如对医疗影像数据进行分析、制作爬虫获取股票信息、自动化实例、从一组看似混乱的数据中找出规律、制作人脸识别系统等。 《Python带我起飞——......一起来看看 《Python带我起飞》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具