mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-10-23 06:47:26 +00:00
Add ability to set cache via query header.
This commit is contained in:
@@ -134,6 +134,8 @@ You can then start using the cache by setting the `ENABLE_GLOBAL_CACHE` environm
|
|||||||
In the case of the `@cached` you can add additional parameters to the directive which will set the cache for specific queries to the provided time.
|
In the case of the `@cached` you can add additional parameters to the directive which will set the cache for specific queries to the provided time.
|
||||||
For example, `query MyCachedQuery @cached(ttl: 90) ....` will set the cache for the query to 90 seconds.
|
For example, `query MyCachedQuery @cached(ttl: 90) ....` will set the cache for the query to 90 seconds.
|
||||||
|
|
||||||
|
You can also set cache for specific query by using `X-Cache-Graphql-Query` header, which will set the cache for the query to the provided time, for example `X-Cache-Graphql-Query: 90` will set the cache for the query to 90 seconds.
|
||||||
|
|
||||||
Since version `0.5.30` the cache is gzipped in the memory, which should optimise the memory usage quite significantly.
|
Since version `0.5.30` the cache is gzipped in the memory, which should optimise the memory usage quite significantly.
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
fiber "github.com/gofiber/fiber/v2"
|
fiber "github.com/gofiber/fiber/v2"
|
||||||
@@ -124,6 +125,15 @@ func processGraphQLRequest(c *fiber.Ctx) error {
|
|||||||
cache_time = cfg.Cache.CacheTTL
|
cache_time = cfg.Cache.CacheTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cache_time == 0 && !cacheFromQuery {
|
||||||
|
cacheQuery := c.Request().Header.Peek("X-Cache-Graphql-Query")
|
||||||
|
if cacheQuery != nil {
|
||||||
|
cache_time, _ = strconv.Atoi(string(cacheQuery))
|
||||||
|
cfg.Logger.Debug("Cache time set via header", map[string]interface{}{"cache_time": cache_time})
|
||||||
|
cacheFromQuery = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wasCached := false
|
wasCached := false
|
||||||
|
|
||||||
// Handling Cache Logic
|
// Handling Cache Logic
|
||||||
|
|||||||
Reference in New Issue
Block a user