Compare commits

...

19 Commits

Author SHA1 Message Date
dtapps e5e4b0f244 - update
4 months ago
dtapps bc07bce311 update
5 months ago
李光春 15776f755b - update
continuous-integration/drone/push Build is passing Details
2 years ago
李光春 8e5b593199 - 删除etcd
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 2c2b2bc62a - update redis
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 d51b35450b - update
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 291c0bbec6 - redis增加debug参数
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 7a0863818e - update
2 years ago
李光春 b63fc33f49 - update
2 years ago
李光春 8d52bda519 - update
2 years ago
李光春 4652fed98f - update
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 979952fd20 - update
2 years ago
李光春 116ade2274 - 增加etcd
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 99a7d4963b - update
continuous-integration/drone/push Build is passing Details
2 years ago
李光春 c1b1b1dc52 - 优化
continuous-integration/drone/push Build is passing Details
2 years ago
李光春 7df99a0ddf - 优化
continuous-integration/drone/push Build is passing Details
2 years ago
李光春 109543b406 - 优化
2 years ago
李光春 8344f4fc6b update big
continuous-integration/drone/push Build is passing Details
2 years ago
李光春 6e11644d0a update
continuous-integration/drone/push Build is passing Details
2 years ago

@ -1,42 +0,0 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1
# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
build:
working_directory: ~/repo
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
docker:
- image: circleci/golang:1.18
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
- checkout
- restore_cache:
keys:
- go-mod-v4-{{ checksum "go.sum" }}
- run:
name: Install Dependencies
command: go mod download
- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run:
name: Run tests
command: |
mkdir -p /tmp/test-reports
gotestsum --junitfile /tmp/test-reports/unit-tests.xml
- store_test_results:
path: /tmp/test-reports
# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
sample: # This is the name of the workflow, feel free to change it to better match your workflow.
# Inside the workflow, you define the jobs you want to run.
jobs:
- build

@ -3,9 +3,15 @@ type: docker
name: clone
steps:
- name: test-golang
- name: Test
image: golang:1.18
commands:
- go env -w GO111MODULE=on
- go env -w GOPROXY=https://goproxy.cn,direct
- go test -v ./...
- go test -v ./...
- name: Benchmark
image: golang:1.18
commands:
- go env -w GO111MODULE=on
- go env -w GOPROXY=https://goproxy.cn,direct
- go test -bench=. -benchmem

@ -1,38 +0,0 @@
name: coverage
on:
push:
branches: [ master ]
paths-ignore:
- '**.md'
pull_request:
branches: [ master ]
paths-ignore:
- '**.md'
jobs:
test:
name: Test with Coverage
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Check out code
uses: actions/checkout@v2
- name: Install dependencies
run: |
go mod download
- name: Run Unit tests
run: |
go test -race -covermode atomic -coverprofile=covprofile ./...
- name: Install goveralls
run: go install github.com/mattn/goveralls@latest
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=covprofile -service=github

@ -1,27 +0,0 @@
name: Go
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Test
run: go test -v ./...
- name: Test
run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic
- name: Coverage
run: bash <(curl -s https://codecov.io/bash)

4
.gitignore vendored

@ -4,7 +4,7 @@
.idea
.vscode
*.log
gomod.sh
/vendor/
/vendor
mod.sh
redis_test.go
memcached_test.go

@ -1,7 +0,0 @@
language: go
go:
- master
script:
- go test -v ./...

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2018 茂名聚合科技有限公司
Copyright (c) 2018 李光春
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

@ -1,25 +1,17 @@
<h1>
<a href="https://www.dtapp.net/">Golang Cache</a>
<a href="https://www.dtapp.net/">Golang</a>
</h1>
📦 Golang 缓存组件
📦 Golang 缓存
[comment]: <> (go)
[![godoc](https://pkg.go.dev/badge/go.dtapp.net/gocache?status.svg)](https://pkg.go.dev/go.dtapp.net/gocache)
[![goproxy.cn](https://goproxy.cn/stats/go.dtapp.net/gocache/badges/download-count.svg)](https://goproxy.cn/stats/go.dtapp.net/gocache)
[![goreportcard.com](https://goreportcard.com/badge/go.dtapp.net/gocache)](https://goreportcard.com/report/go.dtapp.net/gocache)
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/github.com%2Fdtapps%2Fgocache)
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net%2Fgocache)
#### 安装使用
#### 安装
```go
go get -v -u go.dtapp.net/gocache
```shell
go get -v -u go.dtapp.net/gocache@v1.0.14
```
#### 导入
```go
import (
"go.dtapp.net/gocache"
)
```

@ -7,20 +7,26 @@ import (
"time"
)
// BigConfig 配置
type BigConfig struct {
DefaultExpiration time.Duration // 默认过期时间
}
// Big https://github.com/allegro/bigcache
type Big struct {
db *bigcache.BigCache // 驱动
expiration time.Duration // 默认过期时间
config *BigConfig
db *bigcache.BigCache // 驱动
}
// NewBig 实例化
func NewBig(expiration time.Duration) *Big {
c, _ := bigcache.NewBigCache(bigcache.DefaultConfig(expiration))
return &Big{db: c, expiration: expiration}
func NewBig(config *BigConfig) *Big {
c := &Big{config: config}
c.db, _ = bigcache.NewBigCache(bigcache.DefaultConfig(c.config.DefaultExpiration))
return c
}
// Set 插入数据 将只显示给定结构的导出字段 序列化并存储
func (b *Big) Set(key string, value interface{}) error {
func (c *Big) Set(key string, value interface{}) error {
// 将 value 序列化为 bytes
valueBytes, err := serialize(value)
@ -28,14 +34,14 @@ func (b *Big) Set(key string, value interface{}) error {
return err
}
return b.db.Set(key, valueBytes)
return c.db.Set(key, valueBytes)
}
// Get 获取单个数据
func (b *Big) Get(key string) (interface{}, error) {
func (c *Big) Get(key string) (interface{}, error) {
// 获取以 bytes 格式存储的 value
valueBytes, err := b.db.Get(key)
valueBytes, err := c.db.Get(key)
if err != nil {
return nil, err
}

@ -10,9 +10,9 @@ type BigCache struct {
GetterInterface GttInterfaceFunc // 不存在的操作
}
// NewCache 实例化
func (b *Big) NewCache() *BigCache {
return &BigCache{db: b}
// NewCache 实例化组件
func (c *Big) NewCache() *BigCache {
return &BigCache{db: c}
}
// GetInterface 缓存操作

@ -5,31 +5,78 @@ import (
"time"
)
func logBig() *Big {
return NewBig(&BigConfig{
DefaultExpiration: time.Minute * 30,
})
}
func TestBig(t *testing.T) {
newCache := NewBig(time.Minute * 30)
newCache := logBig()
// 字符串
newCache.Set("key1", "测试Big插入数据 1")
// 设置字符串
t.Logf("设置字符串:%+v", newCache.Set("key1", "测试Big插入数据 1"))
key1, _ := newCache.Get("key1")
t.Logf("key1%+v", key1)
t.Logf("读取字符串%+v", key1)
// 结构体
// 设置结构体
type name struct {
Test string `json:"test"`
}
newCache.Set("key2", name{"测试Big插入数据 2"})
t.Logf("设置结构体:%+v", newCache.Set("key2", name{"测试Big插入数据 2"}))
key2, _ := newCache.Get("key2")
t.Logf("key2%+v", key2)
t.Logf("key2%+v", key2.(name))
t.Logf("读取结构体%+v", key2)
t.Logf("读取结构体结果%+v", key2.(name))
// 缓存组件
newCacheCache := newCache.NewCache()
newCacheCache.GetterInterface = func() interface{} {
return name{"测试Big插入数据 3"}
}
//key3Result := &name{}
key3 := newCacheCache.GetInterface("key3")
t.Logf("key3%+v", key3)
t.Logf("key3%+v", key3.(name))
t.Logf("读取缓存组件:%T", key3)
t.Logf("读取缓存组件:%+v", key3.(name))
}
func TestBigSetGet(t *testing.T) {
newCache := logBig()
// 设置结构体
type name struct {
Test string `json:"test1"`
}
t.Logf("设置结构体1%+v", newCache.Set("key2", name{"测试Big插入数据 1"}))
key2, _ := newCache.Get("key2")
t.Logf("读取结构体1%+v", key2)
t.Logf("读取结构体结果1%+v", key2.(name))
t.Logf("设置结构体2%+v", newCache.Set("key2", name{"测试Big插入数据 2"}))
key22, _ := newCache.Get("key2")
t.Logf("读取结构体2%+v", key22)
t.Logf("读取结构体结果2%+v", key22.(name))
}
func TestBigCache(t *testing.T) {
newCache := logBig()
// 设置结构体
type name struct {
Test string `json:"test1"`
}
// 缓存组件
newCacheCache := newCache.NewCache()
newCacheCache.GetterInterface = func() interface{} {
return name{"测试Big插入数据 1"}
}
key1 := newCacheCache.GetInterface("key3")
t.Logf("读取缓存组件1%T", key1)
t.Logf("读取缓存组件1%+v", key1.(name))
}

@ -2,8 +2,6 @@ package gocache
import "time"
const Version = "1.0.4"
var (
DefaultExpiration = time.Minute * 30 // 默认过期时间
)

@ -1 +0,0 @@
package gocache

@ -1 +0,0 @@
package gocache

34
go.go

@ -1,34 +0,0 @@
package gocache
import (
"github.com/patrickmn/go-cache"
"time"
)
// Go https://github.com/patrickmn/go-cache
type Go struct {
db *cache.Cache // 驱动
expiration time.Duration // 默认过期时间
clear time.Duration // 清理过期数据
}
// NewGo 实例化
func NewGo(expiration, clear time.Duration) *Go {
c := cache.New(expiration, clear)
return &Go{db: c, expiration: expiration, clear: clear}
}
// Set 插入数据 并设置过期时间
func (g *Go) Set(key string, value interface{}, expirationTime time.Duration) {
g.db.Set(key, value, expirationTime)
}
// Get 获取单个数据
func (g *Go) Get(key string) (interface{}, bool) {
return g.db.Get(key)
}
// SetDefault 插入数据 并设置为默认过期时间
func (g *Go) SetDefault(key string, value interface{}) {
g.db.Set(key, value, g.expiration)
}

@ -1,20 +1,29 @@
module go.dtapp.net/gocache
go 1.18
go 1.21.5
require (
github.com/allegro/bigcache/v3 v3.0.2
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d
github.com/dgraph-io/ristretto v0.1.0
github.com/go-redis/redis/v8 v8.11.5
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/allegro/bigcache/v3 v3.1.0
github.com/redis/go-redis/v9 v9.4.0
go.dtapp.net/gojson v1.0.4
)
require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/basgys/goxml2json v1.1.0 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
)

103
go.sum

@ -1,45 +1,76 @@
github.com/allegro/bigcache/v3 v3.0.2 h1:AKZCw+5eAaVyNTBmI2fgyPVJhHkdWder3O9IrprcQfI=
github.com/allegro/bigcache/v3 v3.0.2/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I=
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d h1:pVrfxiGfwelyab6n21ZBkbkmbevaf+WvMIiR7sr97hw=
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk=
github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I=
github.com/basgys/goxml2json v1.1.0 h1:4ln5i4rseYfXNd86lGEB+Vi652IsIXIvggKM/BhUKVw=
github.com/basgys/goxml2json v1.1.0/go.mod h1:wH7a5Np/Q4QoECFIU8zTQlZwZkrilY0itPfecMw41Dw=
github.com/bitly/go-simplejson v0.5.1 h1:xgwPbetQScXt1gh9BmoJ6j9JMr3TElvuIyjR8pgdoow=
github.com/bitly/go-simplejson v0.5.1/go.mod h1:YOPVLzCfwK14b4Sff3oP1AmGhI9T9Vsg84etUnlyp+Q=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE=
github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0=
github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/ristretto v0.1.0 h1:Jv3CGQHp9OjuMBSne1485aDpUkTKEcUqF+jm/LuerPI=
github.com/dgraph-io/ristretto v0.1.0/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.4.0 h1:Yzoz33UZw9I/mFhx4MNrB6Fk+XHO1VukNcCa1+lwyKk=
github.com/redis/go-redis/v9 v9.4.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
go.dtapp.net/gojson v1.0.4 h1:9en9iyOOLWoEIo2eKhqt3/Djh/3HhwsTpXxgI9efPRo=
go.dtapp.net/gojson v1.0.4/go.mod h1:G9CMVzNSRkbNzIic/vJqHCOyKtw6BW2YM8Vyn64zfM0=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

@ -1,35 +0,0 @@
package gocache
import (
"time"
)
// GoCache https://github.com/patrickmn/go-cache
type GoCache struct {
db *Go // 驱动
expiration time.Duration // 默认过期时间
GetterInterface GttInterfaceFunc // 不存在的操作
}
// NewCache 实例化
func (g *Go) NewCache(expiration time.Duration) *GoCache {
return &GoCache{db: g, expiration: expiration}
}
// GetInterface 缓存操作
func (gc *GoCache) GetInterface(key string) (ret interface{}) {
f := func() interface{} {
return gc.GetterInterface()
}
// 如果不存在则调用GetterInterface
ret, found := gc.db.Get(key)
if found == false {
gc.db.Set(key, f(), gc.expiration)
ret, _ = gc.db.Get(key)
}
return
}

@ -1,35 +0,0 @@
package gocache
import (
"testing"
"time"
)
func TestGo(t *testing.T) {
newCache := NewGo(5*time.Minute, 10*time.Minute)
// 字符串
newCache.SetDefault("key1", "测试Go插入数据 1")
key1, _ := newCache.Get("key1")
t.Logf("key1%+v", key1)
// 结构体
type name struct {
Test string `json:"test"`
}
newCache.SetDefault("key2", name{"测试Go插入数据 2"})
key2, _ := newCache.Get("key2")
t.Logf("key2%+v", key2)
t.Logf("key2%+v", key2.(name))
// 缓存组件
newCacheCache := newCache.NewCache(5 * time.Minute)
newCacheCache.GetterInterface = func() interface{} {
return name{"测试Go插入数据 3"}
}
key3 := newCacheCache.GetInterface("key3")
t.Logf("key3%+v", key3)
t.Logf("key3%+v", key3.(name))
}

@ -1 +0,0 @@
package gocache

@ -1,46 +0,0 @@
package gocache
import (
"github.com/bradfitz/gomemcache/memcache"
)
// Memcached https://github.com/bradfitz/gomemcache
type Memcached struct {
db *memcache.Client // 驱动
}
// NewMemcached 实例化
func NewMemcached(dns string) *Memcached {
mc := memcache.New(dns)
if mc == nil {
panic("连接失败")
}
return &Memcached{db: mc}
}
// NewMemcachedDb 实例化
func NewMemcachedDb(memcached *memcache.Client) *Memcached {
return &Memcached{db: memcached}
}
// Set 插入数据
func (m *Memcached) Set(key string, value []byte) error {
return m.db.Set(&memcache.Item{Key: key, Value: value})
}
// Get 获取单个数据
func (m *Memcached) Get(key string) (string, error) {
it, err := m.db.Get(key)
if err == memcache.ErrCacheMiss {
return "", memcache.ErrCacheMiss
}
if it.Key == key {
return string(it.Value), nil
}
return "", memcache.ErrCacheMiss
}
// Del 删除单个数据
func (m *Memcached) Del(key string) error {
return m.db.Delete(key)
}

@ -1,57 +0,0 @@
package gocache
import (
"encoding/json"
"github.com/bradfitz/gomemcache/memcache"
)
// MemcachedCache https://github.com/bradfitz/gomemcache
type MemcachedCache struct {
db *Memcached // 驱动
GetterString GttStringFunc // 不存在的操作
GetterInterface GttInterfaceFunc // 不存在的操作
}
// NewCache 实例化
func (m *Memcached) NewCache() *MemcachedCache {
return &MemcachedCache{db: m}
}
// GetString 缓存操作
func (mc *MemcachedCache) GetString(key string) (ret string) {
f := func() string {
return mc.GetterString()
}
// 如果不存在则调用GetterString
ret, err := mc.db.Get(key)
if err == memcache.ErrCacheMiss {
mc.db.Set(key, []byte(f()))
ret, _ = mc.db.Get(key)
}
return
}
// GetInterface 缓存操作
func (mc *MemcachedCache) GetInterface(key string, result interface{}) {
f := func() string {
marshal, _ := json.Marshal(mc.GetterInterface())
return string(marshal)
}
// 如果不存在则调用GetterInterface
ret, err := mc.db.Get(key)
if err == memcache.ErrCacheMiss {
mc.db.Set(key, []byte(f()))
ret, _ = mc.db.Get(key)
}
err = json.Unmarshal([]byte(ret), result)
return
}

@ -2,129 +2,122 @@ package gocache
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
"go.dtapp.net/gojson"
"time"
)
// RedisConfig 配置
type RedisConfig struct {
DefaultExpiration time.Duration // 默认过期时间
Client *redis.Client // 驱动,可选
Debug bool // 调试,可选
}
// Redis https://github.com/go-redis/redis
type Redis struct {
db *redis.Client // 驱动
ctx context.Context // 上下文内容
expiration time.Duration // 默认过期时间
config *RedisConfig // 配置
Client *redis.Client // 驱动
}
// NewRedis 实例化
func NewRedis(addr, password string, dbName int, expiration time.Duration) *Redis {
db := redis.NewClient(&redis.Options{
Addr: addr, // 地址
Password: password, // 密码
DB: dbName, // 数据库
PoolSize: 100, // 连接池大小
})
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_, err := db.Ping(ctx).Result()
if err != nil {
panic(errors.New(fmt.Sprintf("连接失败,%s", err.Error())))
}
return &Redis{db: db, ctx: context.Background(), expiration: expiration}
}
// NewRedisDb 实例化
func NewRedisDb(db *redis.Client, expiration time.Duration) *Redis {
return &Redis{db: db, ctx: context.Background(), expiration: expiration}
func NewRedis(config *RedisConfig) *Redis {
c := &Redis{config: config}
c.Client = config.Client
return c
}
// Set 设置一个key的值
func (r *Redis) Set(key string, value interface{}, expiration time.Duration) (string, error) {
return r.db.Set(r.ctx, key, value, expiration).Result()
r.setLog(key)
return r.Client.Set(context.Background(), key, value, expiration).Result()
}
// SetInterface 设置一个key的值
func (r *Redis) SetInterface(key string, value interface{}, expiration time.Duration) (string, error) {
marshal, _ := json.Marshal(value)
return r.db.Set(r.ctx, key, marshal, expiration).Result()
r.setLog(key)
marshal, _ := gojson.Marshal(value)
return r.Client.Set(context.Background(), key, marshal, expiration).Result()
}
// SetDefaultExpiration 设置一个key的值使用全局默认过期时间
func (r *Redis) SetDefaultExpiration(key string, value interface{}) (string, error) {
return r.db.Set(r.ctx, key, value, r.expiration).Result()
r.setLog(key)
return r.Client.Set(context.Background(), key, value, r.config.DefaultExpiration).Result()
}
// SetInterfaceDefaultExpiration 设置一个key的值使用全局默认过期时间
func (r *Redis) SetInterfaceDefaultExpiration(key string, value interface{}) (string, error) {
marshal, _ := json.Marshal(value)
return r.db.Set(r.ctx, key, marshal, r.expiration).Result()
r.setLog(key)
marshal, _ := gojson.Marshal(value)
return r.Client.Set(context.Background(), key, marshal, r.config.DefaultExpiration).Result()
}
// Get 查询key的值
func (r *Redis) Get(key string) (string, error) {
return r.db.Get(r.ctx, key).Result()
r.getLog(key)
return r.Client.Get(context.Background(), key).Result()
}
// GetInterface 查询key的值
func (r *Redis) GetInterface(key string, result interface{}) error {
ret, err := r.db.Get(r.ctx, key).Result()
r.getLog(key)
ret, err := r.Client.Get(context.Background(), key).Result()
if err != nil {
return err
}
err = json.Unmarshal([]byte(ret), result)
err = gojson.Unmarshal([]byte(ret), result)
return nil
}
// GetSet 设置一个key的值并返回这个key的旧值
func (r *Redis) GetSet(key string, value interface{}) (string, error) {
return r.db.GetSet(r.ctx, key, value).Result()
return r.Client.GetSet(context.Background(), key, value).Result()
}
// SetNX 如果key不存在则设置这个key的值
func (r *Redis) SetNX(key string, value interface{}, expiration time.Duration) error {
return r.db.SetNX(r.ctx, key, value, expiration).Err()
return r.Client.SetNX(context.Background(), key, value, expiration).Err()
}
// SetNXDefaultExpiration 如果key不存在则设置这个key的值使用全局默认过期时间
func (r *Redis) SetNXDefaultExpiration(key string, value interface{}) error {
return r.db.SetNX(r.ctx, key, value, r.expiration).Err()
return r.Client.SetNX(context.Background(), key, value, r.config.DefaultExpiration).Err()
}
// MGet 批量查询key的值
func (r *Redis) MGet(keys ...string) ([]interface{}, error) {
return r.db.MGet(r.ctx, keys...).Result()
return r.Client.MGet(context.Background(), keys...).Result()
}
// MSet 批量设置key的值
// MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})
func (r *Redis) MSet(values map[string]interface{}) error {
return r.db.MSet(r.ctx, values).Err()
return r.Client.MSet(context.Background(), values).Err()
}
// Incr 针对一个key的数值进行递增操作
func (r *Redis) Incr(key string) (int64, error) {
return r.db.Incr(r.ctx, key).Result()
return r.Client.Incr(context.Background(), key).Result()
}
// IncrBy 针对一个key的数值进行递增操作指定每次递增多少
func (r *Redis) IncrBy(key string, value int64) (int64, error) {
return r.db.IncrBy(r.ctx, key, value).Result()
return r.Client.IncrBy(context.Background(), key, value).Result()
}
// Decr 针对一个key的数值进行递减操作
func (r *Redis) Decr(key string) (int64, error) {
return r.db.Decr(r.ctx, key).Result()
return r.Client.Decr(context.Background(), key).Result()
}
// DecrBy 针对一个key的数值进行递减操作指定每次递减多少
func (r *Redis) DecrBy(key string, value int64) (int64, error) {
return r.db.DecrBy(r.ctx, key, value).Result()
return r.Client.DecrBy(context.Background(), key, value).Result()
}
// Del 删除key操作支持批量删除
func (r *Redis) Del(keys ...string) error {
return r.db.Del(r.ctx, keys...).Err()
r.delLog(keys...)
return r.Client.Del(context.Background(), keys...).Err()
}

@ -1,26 +1,36 @@
package gocache
import (
"encoding/json"
"go.dtapp.net/gojson"
"time"
)
// RedisCacheConfig 配置
type RedisCacheConfig struct {
expiration time.Duration // 过期时间
}
// RedisCache https://github.com/go-redis/redis
type RedisCache struct {
db *Redis // 驱动
expiration time.Duration // 默认过期时间
config *RedisCacheConfig
operation *Redis // 操作
GetterString GttStringFunc // 不存在的操作
GetterInterface GttInterfaceFunc // 不存在的操作
}
// NewCache 实例化
func (r *Redis) NewCache(expiration time.Duration) *RedisCache {
return &RedisCache{db: r, expiration: expiration}
func (r *Redis) NewCache(config *RedisCacheConfig) *RedisCache {
c := &RedisCache{config: config}
c.operation = r
return c
}
// NewCacheDefaultExpiration 实例化
func (r *Redis) NewCacheDefaultExpiration() *RedisCache {
return &RedisCache{db: r, expiration: r.expiration}
c := &RedisCache{}
c.config.expiration = r.config.DefaultExpiration
c.operation = r
return c
}
// GetString 缓存操作
@ -31,10 +41,10 @@ func (rc *RedisCache) GetString(key string) (ret string) {
}
// 如果不存在则调用GetterString
ret, err := rc.db.Get(key)
ret, err := rc.operation.Get(key)
if err != nil {
rc.db.Set(key, f(), rc.expiration)
ret, _ = rc.db.Get(key)
rc.operation.Set(key, f(), rc.config.expiration)
ret, _ = rc.operation.Get(key)
}
return
@ -44,19 +54,19 @@ func (rc *RedisCache) GetString(key string) (ret string) {
func (rc *RedisCache) GetInterface(key string, result interface{}) {
f := func() string {
marshal, _ := json.Marshal(rc.GetterInterface())
marshal, _ := gojson.Marshal(rc.GetterInterface())
return string(marshal)
}
// 如果不存在则调用GetterInterface
ret, err := rc.db.Get(key)
ret, err := rc.operation.Get(key)
if err != nil {
rc.db.Set(key, f(), rc.expiration)
ret, _ = rc.db.Get(key)
rc.operation.Set(key, f(), rc.config.expiration)
ret, _ = rc.operation.Get(key)
}
err = json.Unmarshal([]byte(ret), result)
err = gojson.Unmarshal([]byte(ret), result)
return
}

@ -0,0 +1,19 @@
package gocache
import "log"
func (r *Redis) setLog(key string) {
if r.config.Debug == true {
log.Printf("gocache [%s] set\n", key)
}
}
func (r *Redis) getLog(key string) {
if r.config.Debug == true {
log.Printf("gocache [%s] get\n", key)
}
}
func (r *Redis) delLog(key ...string) {
if r.config.Debug == true {
log.Printf("gocache [%s] del\n", key)
}
}

@ -1,39 +0,0 @@
package gocache
import (
"github.com/dgraph-io/ristretto"
)
// Ristretto https://github.com/dgraph-io/ristretto
type Ristretto struct {
db *ristretto.Cache // 驱动
numCounters int64 // 跟踪频率的键数 (10M)
maxCost int64 // 缓存的最大成本1GB
bufferItems int64 // 每个Get缓冲区的密钥数
}
// NewRistretto 实例化
func NewRistretto() *Ristretto {
cache, _ := ristretto.NewCache(&ristretto.Config{
NumCounters: 1e7, // number of keys to track frequency of (10M).
MaxCost: 1 << 30, // maximum cost of cache (1GB).
BufferItems: 64, // number of keys per Get buffer.
})
return &Ristretto{db: cache}
}
// Set 插入数据
func (r *Ristretto) Set(key string, value interface{}, cost int64) {
r.db.Set(key, value, cost)
r.db.Wait()
}
// Get 获取单个数据
func (r *Ristretto) Get(key string) (interface{}, bool) {
return r.db.Get(key)
}
// Del 删除数据
func (r *Ristretto) Del(key string) {
r.db.Del(key)
}

@ -1,30 +0,0 @@
package gocache
// RistrettoCache https://github.com/dgraph-io/ristretto
type RistrettoCache struct {
db *Ristretto // 驱动
GetterInterface GttInterfaceFunc // 不存在的操作
}
// NewCache 实例化
func (r *Ristretto) NewCache() *RistrettoCache {
return &RistrettoCache{db: r}
}
// GetInterface 缓存操作
func (rc *RistrettoCache) GetInterface(key string) (ret interface{}) {
f := func() interface{} {
return rc.GetterInterface()
}
// 如果不存在则调用GetterInterface
ret, found := rc.db.Get(key)
if found == false {
rc.db.Set(key, f(), 1)
ret, _ = rc.db.Get(key)
}
return
}

@ -1,40 +0,0 @@
package gocache
import (
"testing"
)
func TestRistretto(t *testing.T) {
newCache := NewRistretto()
// 字符串
newCache.Set("key1", "测试Ristretto插入数据 1", 1)
key1, _ := newCache.Get("key1")
t.Logf("key1%+v", key1)
newCache.Del("key1")
key1, _ = newCache.Get("key1")
t.Logf("key1%+v", key1)
// 结构体
type name struct {
Test string `json:"test"`
}
newCache.Set("key2", name{"测试Ristretto插入数据 2"}, 1)
key2, _ := newCache.Get("key2")
t.Logf("key2%+v", key2)
t.Logf("key2%+v", key2.(name))
newCache.Del("key2")
key2, _ = newCache.Get("key2")
t.Logf("key2%+v", key2)
// 缓存组件
newCacheCache := newCache.NewCache()
newCacheCache.GetterInterface = func() interface{} {
return name{"测试Ristretto插入数据 3"}
}
key3 := newCacheCache.GetInterface("key3")
t.Logf("key3%+v", key3)
t.Logf("key3%+v", key3.(name))
}

@ -0,0 +1,3 @@
package gocache
const Version = "1.0.14"

@ -0,0 +1,13 @@
package gocache
import "testing"
func TestVersion(t *testing.T) {
t.Log(Version)
}
func BenchmarkVersion(b *testing.B) {
for i := 0; i < b.N; i++ {
b.Log(Version)
}
}
Loading…
Cancel
Save