|
|
@@ -145,12 +145,13 @@ func SiteCache(store persistence.CacheStore, expire time.Duration) gin.HandlerFu
|
|
|
}
|
|
|
}
|
|
|
c.Writer.Write(cache.Data)
|
|
|
+ c.Abort()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// CachePage Decorator
|
|
|
-func CachePage(store persistence.CacheStore, expire time.Duration, handle gin.HandlerFunc) gin.HandlerFunc {
|
|
|
+func CachePage(store persistence.CacheStore, expire time.Duration) gin.HandlerFunc {
|
|
|
return func(c *gin.Context) {
|
|
|
var cache responseCache
|
|
|
url := c.Request.URL
|
|
|
@@ -162,8 +163,7 @@ func CachePage(store persistence.CacheStore, expire time.Duration, handle gin.Ha
|
|
|
// replace writer
|
|
|
writer := newCachedWriter(store, expire, c.Writer, key)
|
|
|
c.Writer = writer
|
|
|
- handle(c)
|
|
|
-
|
|
|
+ c.Next()
|
|
|
// Drop caches of aborted contexts
|
|
|
if c.IsAborted() {
|
|
|
store.Delete(key)
|
|
|
@@ -176,12 +176,13 @@ func CachePage(store persistence.CacheStore, expire time.Duration, handle gin.Ha
|
|
|
}
|
|
|
}
|
|
|
c.Writer.Write(cache.Data)
|
|
|
+ c.Abort()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// CachePageWithoutQuery add ability to ignore GET query parameters.
|
|
|
-func CachePageWithoutQuery(store persistence.CacheStore, expire time.Duration, handle gin.HandlerFunc) gin.HandlerFunc {
|
|
|
+func CachePageWithoutQuery(store persistence.CacheStore, expire time.Duration) gin.HandlerFunc {
|
|
|
return func(c *gin.Context) {
|
|
|
var cache responseCache
|
|
|
key := CreateKey(c.Request.URL.Path)
|
|
|
@@ -192,7 +193,7 @@ func CachePageWithoutQuery(store persistence.CacheStore, expire time.Duration, h
|
|
|
// replace writer
|
|
|
writer := newCachedWriter(store, expire, c.Writer, key)
|
|
|
c.Writer = writer
|
|
|
- handle(c)
|
|
|
+ c.Next()
|
|
|
} else {
|
|
|
c.Writer.WriteHeader(cache.Status)
|
|
|
for k, vals := range cache.Header {
|
|
|
@@ -201,14 +202,15 @@ func CachePageWithoutQuery(store persistence.CacheStore, expire time.Duration, h
|
|
|
}
|
|
|
}
|
|
|
c.Writer.Write(cache.Data)
|
|
|
+ c.Abort()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// CachePageAtomic Decorator
|
|
|
-func CachePageAtomic(store persistence.CacheStore, expire time.Duration, handle gin.HandlerFunc) gin.HandlerFunc {
|
|
|
+func CachePageAtomic(store persistence.CacheStore, expire time.Duration) gin.HandlerFunc {
|
|
|
var m sync.Mutex
|
|
|
- p := CachePage(store, expire, handle)
|
|
|
+ p := CachePage(store, expire)
|
|
|
return func(c *gin.Context) {
|
|
|
m.Lock()
|
|
|
defer m.Unlock()
|
|
|
@@ -216,7 +218,7 @@ func CachePageAtomic(store persistence.CacheStore, expire time.Duration, handle
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func CachePageWithoutHeader(store persistence.CacheStore, expire time.Duration, handle gin.HandlerFunc) gin.HandlerFunc {
|
|
|
+func CachePageWithoutHeader(store persistence.CacheStore, expire time.Duration) gin.HandlerFunc {
|
|
|
return func(c *gin.Context) {
|
|
|
var cache responseCache
|
|
|
url := c.Request.URL
|
|
|
@@ -228,7 +230,7 @@ func CachePageWithoutHeader(store persistence.CacheStore, expire time.Duration,
|
|
|
// replace writer
|
|
|
writer := newCachedWriter(store, expire, c.Writer, key)
|
|
|
c.Writer = writer
|
|
|
- handle(c)
|
|
|
+ c.Next()
|
|
|
|
|
|
// Drop caches of aborted contexts
|
|
|
if c.IsAborted() {
|
|
|
@@ -237,6 +239,7 @@ func CachePageWithoutHeader(store persistence.CacheStore, expire time.Duration,
|
|
|
} else {
|
|
|
c.Writer.WriteHeader(cache.Status)
|
|
|
c.Writer.Write(cache.Data)
|
|
|
+ c.Abort()
|
|
|
}
|
|
|
}
|
|
|
}
|