From 7066710e89bc7f2507739b4c92821505e9fe7a49 Mon Sep 17 00:00:00 2001 From: Julia Qiu Date: Mon, 7 Jun 2021 20:52:01 -0700 Subject: [PATCH] refactor wfcache api --- README.md | 4 ++-- dynamodb/dynamodb_test.go | 2 +- redis/redis_test.go | 2 +- cache.go => wfcache.go | 6 +++--- cache_test.go => wfcache_test.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) rename cache.go => wfcache.go (96%) rename cache_test.go => wfcache_test.go (96%) diff --git a/README.md b/README.md index 5a5afe7..7c09ce2 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ import ( dynamodb "github.com/juliaqiuxy/wfcache/dynamodb" ) -c, err := wfcache.Create( +c, err := wfcache.New( basic.Create(5 * time.Minute), bigcache.Create(2 * time.Hour), dynamodb.Create(dynamodbClient, "my-cache-table", 24 * time.Hour), @@ -69,7 +69,7 @@ func onFinishStorageOp(span interface{}) { span.(ddtrace.Span).Finish() } -wfcache.CreateWithHooks( +wfcache.NewWithHooks( onStartStorageOp, onFinishStorageOp, basic.Create(5 * time.Minute), diff --git a/dynamodb/dynamodb_test.go b/dynamodb/dynamodb_test.go index 1172ac8..55824fb 100644 --- a/dynamodb/dynamodb_test.go +++ b/dynamodb/dynamodb_test.go @@ -55,7 +55,7 @@ func DynamodbClient() *dynamodb.DynamoDB { func TestDynamoDb(t *testing.T) { dynamodbClient := DynamodbClient() - c, _ := wfcache.Create( + c, _ := wfcache.New( dynamodbAdapter.Create(dynamodbClient, "tests", 6*time.Hour), ) diff --git a/redis/redis_test.go b/redis/redis_test.go index 9d9f850..1c0c533 100644 --- a/redis/redis_test.go +++ b/redis/redis_test.go @@ -53,7 +53,7 @@ func RedisClient() *redis.Client { func TestRedis(t *testing.T) { r := RedisClient() - c, _ := wfcache.Create( + c, _ := wfcache.New( redisAdapter.Create(r, 6*time.Hour), ) diff --git a/cache.go b/wfcache.go similarity index 96% rename from cache.go rename to wfcache.go index daee68a..f9931e6 100644 --- a/cache.go +++ b/wfcache.go @@ -47,15 +47,15 @@ var nosop = func(ctx context.Context, opName string) interface{} { } var nofop = func(input interface{}) {} -func Create(maker StorageMaker, otherMakers ...StorageMaker) (*Cache, error) { - return CreateWithHooks( +func New(maker StorageMaker, otherMakers ...StorageMaker) (*Cache, error) { + return NewWithHooks( nosop, nofop, maker, otherMakers...) } -func CreateWithHooks(sop StartStorageOp, fop FinishStorageOp, maker StorageMaker, otherMakers ...StorageMaker) (*Cache, error) { +func NewWithHooks(sop StartStorageOp, fop FinishStorageOp, maker StorageMaker, otherMakers ...StorageMaker) (*Cache, error) { var c *Cache makers := append([]StorageMaker{maker}, otherMakers...) diff --git a/cache_test.go b/wfcache_test.go similarity index 96% rename from cache_test.go rename to wfcache_test.go index de5c825..993085e 100644 --- a/cache_test.go +++ b/wfcache_test.go @@ -13,7 +13,7 @@ import ( ) func TestWfCache(t *testing.T) { - c, _ := wfcache.Create( + c, _ := wfcache.New( basicAdapter.Create(5*time.Minute), bigCacheAdapter.Create(30*time.Minute), )