1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

improve cache handler, embracing #2210 too

This commit is contained in:
Gerasimos (Makis) Maropoulos
2023-09-26 21:14:57 +03:00
parent d03757b996
commit 28f49cd50d
17 changed files with 381 additions and 216 deletions

10
cache/cache_test.go vendored
View File

@@ -162,10 +162,10 @@ func TestCacheValidator(t *testing.T) {
ctx.Write([]byte(expectedBodyStr))
}
validCache := cache.Cache(cacheDuration)
app.Get("/", validCache.ServeHTTP, h)
validCache := cache.Handler(cacheDuration)
app.Get("/", validCache, h)
managedCache := cache.Cache(cacheDuration)
managedCache := cache.Cache(cache.MaxAge(cacheDuration))
managedCache.AddRule(rule.Validator([]rule.PreValidator{
func(ctx *context.Context) bool {
// should always invalid for cache, don't bother to go to try to get or set cache
@@ -173,7 +173,7 @@ func TestCacheValidator(t *testing.T) {
},
}, nil))
managedCache2 := cache.Cache(cacheDuration)
managedCache2 := cache.Cache(cache.MaxAge(cacheDuration))
managedCache2.AddRule(rule.Validator(nil,
[]rule.PostValidator{
func(ctx *context.Context) bool {
@@ -183,7 +183,7 @@ func TestCacheValidator(t *testing.T) {
},
))
app.Get("/valid", validCache.ServeHTTP, h)
app.Get("/valid", validCache, h)
app.Get("/invalid", managedCache.ServeHTTP, h)
app.Get("/invalid2", managedCache2.ServeHTTP, func(ctx *context.Context) {