1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-23 15:23:58 +00:00

Merge pull request #829 from Fenny/master

📦 introduce cache mw
This commit is contained in:
Fenny 2020-09-26 11:22:58 +02:00 committed by GitHub
commit fbf03afa43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 14 deletions

3
.github/CODEOWNERS vendored
View File

@ -1 +1,4 @@
* @gofiber/maintainers
middleware/filesystem/* @arsmn
middleware/cache/* @codemicro

View File

@ -1,5 +1,5 @@
# Cache
Cache middleware for [Fiber](https://github.com/gofiber/fiber) designed to intercept responses and cache them. This middleware will cache the `Body`, `Content-Type` and `StatusCode` using the `c.Path()` as unique identifier. Special thanks to [@codemicro](github.com/codemicro/fiber-cache).
Cache middleware for [Fiber](https://github.com/gofiber/fiber) designed to intercept responses and cache them. This middleware will cache the `Body`, `Content-Type` and `StatusCode` using the `c.Path()` as unique identifier. Special thanks to [@codemicro](github.com/codemicro/fiber-cache) for creating this middleware for Fiber core!
### Table of Contents
- [Signatures](#signatures)

View File

@ -1,4 +1,5 @@
// Special thanks to @codemicro for helping with this middleware: github.com/codemicro/fiber-cache
// Special thanks to @codemicro for moving this to fiber core
// Original middleware: github.com/codemicro/fiber-cache
package cache
import (
@ -19,14 +20,6 @@ type Config struct {
//
// Optional. Default: 5 * time.Minute
Expiration time.Duration
// // Hydrate is run before the response is returned to the client.
// // Because this middleware is backend-agnostic, it makes no assumptions
// // about what you want to do with cached response other than caching the statuscode,
// // content-type and response body. Hydrate allows you to alter the cached response.
// //
// // Optional. Default: nil
// Hydrate fiber.Handler
}
// ConfigDefault is the default config
@ -117,10 +110,6 @@ func New(config ...Config) fiber.Handler {
c.Response().SetBodyRaw(resp.body)
c.Response().SetStatusCode(resp.statusCode)
c.Response().Header.SetContentTypeBytes(resp.contentType)
// // Hydrate response if defined
// if cfg.Hydrate != nil {
// return cfg.Hydrate(c)
// }
return nil
}

4
middleware/cache/cache_test.go vendored Normal file
View File

@ -0,0 +1,4 @@
// Special thanks to @codemicro for moving this to fiber core
// Original middleware: github.com/codemicro/fiber-cache
package cache