Skip to content

Commit

Permalink
新增缓存freeCache
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzeyi committed Oct 11, 2022
1 parent e60684d commit aa29d00
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
3 changes: 2 additions & 1 deletion drivers/strategy/cache-strategy/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func init() {
actuator := newtActuator()
actuatorSet = actuator
strategy.AddStrategyHandler(actuator)
cache.NewCache()
}

type ActuatorSet interface {
Expand Down Expand Up @@ -120,7 +121,7 @@ func (a *tActuator) DoFilter(ctx eocontext.EoContext, next eocontext.IChain) err
}
}

localCache = &cache.Cache{
localCache = &cache.ResponseData{
Header: header,
Body: httpCtx.Response().GetBody(),
}
Expand Down
27 changes: 21 additions & 6 deletions drivers/strategy/cache-strategy/cache/cache.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
package cache

//todo 本地缓存demo
import (
"encoding/json"
"github.com/coocood/freecache"
)

type Cache struct {
var freeCache *freecache.Cache

func NewCache() {
freeCache = freecache.NewCache(0)
}

type ResponseData struct {
Header map[string]string
Body []byte
}

func SetCache(uri string, cache *Cache, validTime int) {

func SetCache(uri string, data *ResponseData, validTime int) {
bytes, _ := json.Marshal(data)
_ = freeCache.Set([]byte(uri), bytes, validTime)
}

func GetCache(uri string) *Cache {
return nil
func GetCache(uri string) *ResponseData {
bytes, _ := freeCache.Get([]byte(uri))
data := new(ResponseData)
if err := json.Unmarshal(bytes, data); err != nil {
return nil
}
return data
}
15 changes: 3 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.17

require (
github.com/Shopify/sarama v1.32.0
github.com/coocood/freecache v1.2.2
github.com/eolinker/eosc v0.6.2
github.com/go-basic/uuid v1.0.0
github.com/hashicorp/consul/api v1.9.1
Expand All @@ -20,7 +21,7 @@ require (
github.com/andybalholm/brotli v1.0.2 // indirect
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
Expand All @@ -32,12 +33,10 @@ require (
github.com/fatih/color v1.9.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gops v0.3.25 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
Expand All @@ -56,10 +55,8 @@ require (
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 // indirect
github.com/klauspost/compress v1.14.4 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
Expand All @@ -68,23 +65,18 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shirou/gopsutil/v3 v3.22.4 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/stretchr/testify v1.7.1 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
Expand All @@ -111,7 +103,6 @@ require (
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
rsc.io/goversion v1.2.0 // indirect
)

replace github.com/eolinker/eosc => ../eosc

0 comments on commit aa29d00

Please sign in to comment.