From ce6842dac11f29cd829d49425125f048c9342ae7 Mon Sep 17 00:00:00 2001 From: Minh Vuong Date: Fri, 22 Apr 2022 00:25:43 +0700 Subject: [PATCH] feat: add caching debug headers directive. --- Caddyfile | 92 ++++++++++++++++++++++++++++-------------------------- caching.go | 4 +++ 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/Caddyfile b/Caddyfile index 1b692ad..ba3068b 100644 --- a/Caddyfile +++ b/Caddyfile @@ -2,59 +2,61 @@ {$GBOX_GLOBAL_DIRECTIVES} } -{$GBOX_SERVER_NAME:localhost} { - log { - level {$GBOX_LOG_LEVEL:INFO} - } +{$GBOX_SERVER_NAME:localhost} - @admin_auth { - path /admin/graphql - method POST - expression `{$GBOX_ENABLED_CACHING:true} == true && {$GBOX_ENABLED_ADMIN_AUTH:false} == true` - } +log - @metrics { - path {$GBOX_METRICS_PATH:/metrics} - method GET - expression `{$GBOX_ENABLED_METRICS:false} == true` - } +@admin_auth { + path /admin/graphql + method POST + expression `{$GBOX_ENABLED_CACHING:true} == true && {$GBOX_ENABLED_ADMIN_AUTH:false} == true` +} - route { - encode gzip +@metrics { + path {$GBOX_METRICS_PATH:/metrics} + method GET + expression `{$GBOX_ENABLED_METRICS:false} == true` +} - metrics @metrics +route { + encode gzip - basicauth @admin_auth bcrypt { - {$GBOX_ADMIN_USERNAME:gbox} {$GBOX_ADMIN_PASSWORD:JDJhJDE0JHBXUk5YMjVRYlRtTjN3SERiU0Rrei4uMW4ub0FhaHZlY0hnbWtBMUNSLnhmeEUuUDVOOW5l} - } + metrics @metrics - gbox { - upstream {$GBOX_UPSTREAM} { - {$GBOX_UPSTREAM_REVERSE_PROXY_DIRECTIVES} + basicauth @admin_auth bcrypt { + {$GBOX_ADMIN_USERNAME:gbox} {$GBOX_ADMIN_PASSWORD:JDJhJDE0JHBXUk5YMjVRYlRtTjN3SERiU0Rrei4uMW4ub0FhaHZlY0hnbWtBMUNSLnhmeEUuUDVOOW5l} + } + + gbox { + upstream {$GBOX_UPSTREAM} { + {$GBOX_UPSTREAM_REVERSE_PROXY_DIRECTIVES} + } + fetch_schema_interval {$GBOX_FETCH_SCHEMA_INTERVAL:10m} + complexity { + enabled {$GBOX_ENABLED_COMPLEXITY:true} + node_count_limit {$GBOX_NODE_COUNT_LIMIT:60} + max_complexity {$GBOX_MAX_COMPLEXITY:60} + max_depth {$GBOX_MAX_DEPTH:15} + } + disabled_introspection {$GBOX_DISABLED_INTROSPECTION:false} + disabled_playgrounds {$GBOX_DISABLED_PLAYGROUNDS:false} + caching { + enabled {$GBOX_ENABLED_CACHING:true} + store_dsn {$GBOX_STORE_DSN:freecache://?cache_size=5368709120} + rules { + {$GBOX_CACHING_RULES} } - fetch_schema_interval {$GBOX_FETCH_SCHEMA_INTERVAL:10m} - complexity { - enabled {$GBOX_ENABLED_COMPLEXITY:true} - node_count_limit {$GBOX_NODE_COUNT_LIMIT:60} - max_complexity {$GBOX_MAX_COMPLEXITY:60} - max_depth {$GBOX_MAX_DEPTH:15} + varies { + {$GBOX_CACHING_VARIES} } - disabled_introspection {$GBOX_DISABLED_INTROSPECTION:false} - disabled_playgrounds {$GBOX_DISABLED_PLAYGROUNDS:false} - caching { - enabled {$GBOX_ENABLED_CACHING:true} - store_dsn {$GBOX_STORE_DSN:freecache://?cache_size=5368709120} - rules { - {$GBOX_CACHING_RULES} - } - varies { - {$GBOX_CACHING_VARIES} - } - auto_invalidate_cache {$GBOX_AUTO_INVALIDATE_CACHE:true} + type_keys { + {$GBOX_CACHING_TYPE_KEYS} } - {$GBOX_EXTRA_DIRECTIVES} + auto_invalidate_cache {$GBOX_AUTO_INVALIDATE_CACHE:true} + debug_headers {$GBOX_CACHING_DEBUG_HEADERS:true} } - - respond /healthz "OK" + {$GBOX_EXTRA_DIRECTIVES} } -} \ No newline at end of file + + respond /healthz "OK" +} diff --git a/caching.go b/caching.go index 4747cd2..fa2506c 100644 --- a/caching.go +++ b/caching.go @@ -51,6 +51,10 @@ type Caching struct { // of this query have type User with id's 3, all cached query result related with id 3 of User type will be purged. AutoInvalidate bool + // Add debug headers like query result cache key, + // plan cache key and query result had types keys or not... + DebugHeaders bool + logger *zap.Logger store *CachingStore ctxBackground context.Context