Skip to content

Commit

Permalink
Merge pull request #9 from kenshin579/feat/#8-export
Browse files Browse the repository at this point in the history
[#8] export field for config
  • Loading branch information
kenshin579 authored Jul 8, 2023
2 parents 3ae9468 + 5dc893e commit f87cd62
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
24 changes: 12 additions & 12 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type (
// returns true or false, whether it exists or not.
Get(key uint64) ([]byte, bool)

// Set caches a response for a given key until an expiration date.
// Set caches a response for a given key until an Expiration date.
Set(key uint64, response []byte, expiration time.Time)

// Release frees cache for a given key.
Expand All @@ -70,9 +70,9 @@ type (

Store CacheStore

expiration time.Duration
includePaths []string
excludePaths []string
Expiration time.Duration
IncludePaths []string
ExcludePaths []string
}

// CacheResponse is the cached response data structure.
Expand All @@ -83,8 +83,8 @@ type (
// Header is the cached response header.
Header http.Header `json:"header"`

// Expiration is the cached response expiration date.
Expiration time.Time `json:"expiration"`
// Expiration is the cached response Expiration date.
Expiration time.Time `json:"Expiration"`

// LastAccess is the last date a cached response was accessed.
// Used by LRU and MRU algorithms.
Expand All @@ -100,7 +100,7 @@ var (
// DefaultCacheConfig defines default values for CacheConfig
DefaultCacheConfig = CacheConfig{
Skipper: middleware.DefaultSkipper,
expiration: 3 * time.Minute,
Expiration: 3 * time.Minute,
}
)

Expand Down Expand Up @@ -128,8 +128,8 @@ func CacheWithConfig(config CacheConfig) echo.MiddlewareFunc {
if config.Store == nil {
panic("Store configuration must be provided")
}
if config.expiration < 1 {
panic("Cache expiration must be provided")
if config.Expiration < 1 {
panic("Cache Expiration must be provided")
}

return func(next echo.HandlerFunc) echo.HandlerFunc {
Expand Down Expand Up @@ -194,7 +194,7 @@ func CacheWithConfig(config CacheConfig) echo.MiddlewareFunc {
response := CacheResponse{
Value: value,
Header: writer.Header(),
Expiration: now.Add(config.expiration),
Expiration: now.Add(config.Expiration),
LastAccess: now,
Frequency: 1,
}
Expand All @@ -211,7 +211,7 @@ func CacheWithConfig(config CacheConfig) echo.MiddlewareFunc {
}

func (c *CacheConfig) isIncludePaths(URL string) bool {
for _, p := range c.includePaths {
for _, p := range c.IncludePaths {
if strings.Contains(URL, p) {
return true
}
Expand All @@ -220,7 +220,7 @@ func (c *CacheConfig) isIncludePaths(URL string) bool {
}

func (c *CacheConfig) isExcludePaths(URL string) bool {
for _, p := range c.excludePaths {
for _, p := range c.ExcludePaths {
if strings.Contains(URL, p) {
return true
}
Expand Down
18 changes: 9 additions & 9 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Test_CacheWithConfig(t *testing.T) {
wants wants
}{
{
name: "test includePaths",
name: "test IncludePaths",
args: args{
method: http.MethodGet,
url: "http://foo.bar/test-1",
Expand All @@ -66,8 +66,8 @@ func Test_CacheWithConfig(t *testing.T) {
Capacity: 5,
Algorithm: LFU,
}),
expiration: 5 * time.Second,
includePaths: []string{"foo.bar"},
Expiration: 5 * time.Second,
IncludePaths: []string{"foo.bar"},
},
},
wants: wants{
Expand All @@ -76,7 +76,7 @@ func Test_CacheWithConfig(t *testing.T) {
},
},
{
name: "test excludePaths",
name: "test ExcludePaths",
args: args{
method: http.MethodGet,
url: "http://foo.bar/test-1",
Expand All @@ -85,8 +85,8 @@ func Test_CacheWithConfig(t *testing.T) {
Capacity: 5,
Algorithm: LFU,
}),
expiration: 5 * time.Second,
excludePaths: []string{"foo.bar"},
Expiration: 5 * time.Second,
ExcludePaths: []string{"foo.bar"},
},
},
wants: wants{
Expand All @@ -104,8 +104,8 @@ func Test_CacheWithConfig(t *testing.T) {
Capacity: 5,
Algorithm: LFU,
}),
expiration: 5 * time.Second,
includePaths: []string{"foo.bar"},
Expiration: 5 * time.Second,
IncludePaths: []string{"foo.bar"},
},
},
wants: wants{
Expand Down Expand Up @@ -192,7 +192,7 @@ func Test_nytes(t *testing.T) {
}

bytes := r.bytes()
assert.Equal(t, `{"value":"dGVzdA==","header":null,"expiration":"0001-01-01T00:00:00Z","lastAccess":"0001-01-01T00:00:00Z","frequency":1}`, string(bytes))
assert.Equal(t, `{"value":"dGVzdA==","header":null,"Expiration":"0001-01-01T00:00:00Z","lastAccess":"0001-01-01T00:00:00Z","frequency":1}`, string(bytes))
}

func Test_keyAsString(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (suite *cacheRedisStoreTestSuite) SetupSuite() {
suite.echo = echo.New()
suite.echo.Use(CacheWithConfig(CacheConfig{
Store: store,
expiration: 5 * time.Second,
includePaths: []string{"/test"},
Expiration: 5 * time.Second,
IncludePaths: []string{"/test"},
}))
}

Expand Down

0 comments on commit f87cd62

Please sign in to comment.