Skip to content

Commit

Permalink
refactor wfcache api
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaqiuxy committed Jun 8, 2021
1 parent f9f90f7 commit 7066710
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -69,7 +69,7 @@ func onFinishStorageOp(span interface{}) {
span.(ddtrace.Span).Finish()
}

wfcache.CreateWithHooks(
wfcache.NewWithHooks(
onStartStorageOp,
onFinishStorageOp,
basic.Create(5 * time.Minute),
Expand Down
2 changes: 1 addition & 1 deletion dynamodb/dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)

Expand Down
2 changes: 1 addition & 1 deletion redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)

Expand Down
6 changes: 3 additions & 3 deletions cache.go → wfcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand Down
2 changes: 1 addition & 1 deletion cache_test.go → wfcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down

0 comments on commit 7066710

Please sign in to comment.