-
Notifications
You must be signed in to change notification settings - Fork 329
in memory and Redis cache configuration #2155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
170feeb
in memory and Redis cache configuration
62ac7dd
Merge branch 'dev' into geal/caching-configuration
9c2c431
Merge branch 'dev' into geal/caching-configuration
3537718
changelog
aae0455
add docs
60bcf15
consistent emoji usage
a70a05e
rename cache to experimental_cache in configuration
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ use serde_json::Map; | |
| use serde_json::Value; | ||
| use thiserror::Error; | ||
|
|
||
| use crate::cache::DEFAULT_CACHE_CAPACITY; | ||
| use crate::configuration::schema::Mode; | ||
| use crate::executable::APOLLO_ROUTER_DEV_ENV; | ||
| use crate::plugin::plugins; | ||
|
|
@@ -485,16 +486,19 @@ pub(crate) struct Supergraph { | |
| #[serde(default = "default_defer_support")] | ||
| pub(crate) preview_defer_support: bool, | ||
|
|
||
| #[cfg(feature = "experimental_cache")] | ||
| /// URLs of Redis cache used for query planning | ||
| pub(crate) cache_redis_urls: Option<Vec<String>>, | ||
| /// Configures automatic persisted queries | ||
| #[serde(default)] | ||
| pub(crate) apq: Apq, | ||
|
|
||
| /// Query planning options | ||
| #[serde(default)] | ||
| pub(crate) query_planning: QueryPlanning, | ||
| } | ||
|
|
||
| fn default_defer_support() -> bool { | ||
| true | ||
| } | ||
|
|
||
| #[cfg(feature = "experimental_cache")] | ||
| #[buildstructor::buildstructor] | ||
| impl Supergraph { | ||
| #[builder] | ||
|
|
@@ -503,19 +507,20 @@ impl Supergraph { | |
| path: Option<String>, | ||
| introspection: Option<bool>, | ||
| preview_defer_support: Option<bool>, | ||
| cache_redis_urls: Option<Vec<String>>, | ||
| apq: Option<Apq>, | ||
| query_planning: Option<QueryPlanning>, | ||
| ) -> Self { | ||
| Self { | ||
| listen: listen.unwrap_or_else(default_graphql_listen), | ||
| path: path.unwrap_or_else(default_graphql_path), | ||
| introspection: introspection.unwrap_or_else(default_graphql_introspection), | ||
| preview_defer_support: preview_defer_support.unwrap_or_else(default_defer_support), | ||
| cache_redis_urls, | ||
| apq: apq.unwrap_or_default(), | ||
| query_planning: query_planning.unwrap_or_default(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "experimental_cache")] | ||
| #[cfg(test)] | ||
| #[buildstructor::buildstructor] | ||
| impl Supergraph { | ||
|
|
@@ -525,75 +530,74 @@ impl Supergraph { | |
| path: Option<String>, | ||
| introspection: Option<bool>, | ||
| preview_defer_support: Option<bool>, | ||
| cache_redis_urls: Option<Vec<String>>, | ||
| apq: Option<Apq>, | ||
| query_planning: Option<QueryPlanning>, | ||
| ) -> Self { | ||
| Self { | ||
| listen: listen.unwrap_or_else(test_listen), | ||
| path: path.unwrap_or_else(default_graphql_path), | ||
| introspection: introspection.unwrap_or_else(default_graphql_introspection), | ||
| preview_defer_support: preview_defer_support.unwrap_or_else(default_defer_support), | ||
| cache_redis_urls, | ||
| apq: apq.unwrap_or_default(), | ||
| query_planning: query_planning.unwrap_or_default(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(feature = "experimental_cache"))] | ||
| #[buildstructor::buildstructor] | ||
| impl Supergraph { | ||
| #[builder] | ||
| pub(crate) fn new( | ||
| listen: Option<ListenAddr>, | ||
| path: Option<String>, | ||
| introspection: Option<bool>, | ||
| preview_defer_support: Option<bool>, | ||
| ) -> Self { | ||
| Self { | ||
| listen: listen.unwrap_or_else(default_graphql_listen), | ||
| path: path.unwrap_or_else(default_graphql_path), | ||
| introspection: introspection.unwrap_or_else(default_graphql_introspection), | ||
| preview_defer_support: preview_defer_support.unwrap_or_else(default_defer_support), | ||
| } | ||
| impl Default for Supergraph { | ||
| fn default() -> Self { | ||
| Self::builder().build() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(feature = "experimental_cache"))] | ||
| #[cfg(test)] | ||
| #[buildstructor::buildstructor] | ||
| impl Supergraph { | ||
| #[builder] | ||
| pub(crate) fn fake_new( | ||
| listen: Option<ListenAddr>, | ||
| path: Option<String>, | ||
| introspection: Option<bool>, | ||
| preview_defer_support: Option<bool>, | ||
| ) -> Self { | ||
| Self { | ||
| listen: listen.unwrap_or_else(test_listen), | ||
| path: path.unwrap_or_else(default_graphql_path), | ||
| introspection: introspection.unwrap_or_else(default_graphql_introspection), | ||
| preview_defer_support: preview_defer_support.unwrap_or_else(default_defer_support), | ||
| } | ||
| } | ||
| #[derive(Debug, Clone, Default, Deserialize, Serialize, JsonSchema)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub(crate) struct Apq { | ||
| pub(crate) experimental_cache: Cache, | ||
| } | ||
|
|
||
| impl Supergraph { | ||
| #[derive(Debug, Clone, Default, Deserialize, Serialize, JsonSchema)] | ||
| #[serde(deny_unknown_fields)] | ||
| pub(crate) struct QueryPlanning { | ||
| pub(crate) experimental_cache: Cache, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need 2 different structs instead of one ? |
||
| } | ||
|
|
||
| #[derive(Debug, Clone, Default, Deserialize, Serialize, JsonSchema)] | ||
| #[serde(deny_unknown_fields)] | ||
|
|
||
| pub(crate) struct Cache { | ||
| /// Configures the in memory cache (always active) | ||
| pub(crate) in_memory: InMemoryCache, | ||
| #[cfg(feature = "experimental_cache")] | ||
| pub(crate) fn cache(&self) -> Option<Vec<String>> { | ||
| self.cache_redis_urls.clone() | ||
| } | ||
| /// Configures and activates the Redis cache | ||
| pub(crate) redis: Option<RedisCache>, | ||
| } | ||
|
|
||
| #[cfg(not(feature = "experimental_cache"))] | ||
| pub(crate) fn cache(&self) -> Option<Vec<String>> { | ||
| None | ||
| } | ||
| #[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)] | ||
| #[serde(deny_unknown_fields)] | ||
| /// In memory cache configuration | ||
| pub(crate) struct InMemoryCache { | ||
| /// Number of entries in the Least Recently Used cache | ||
| pub(crate) limit: usize, | ||
| } | ||
|
|
||
| impl Default for Supergraph { | ||
| impl Default for InMemoryCache { | ||
| fn default() -> Self { | ||
| Self::builder().build() | ||
| Self { | ||
| limit: DEFAULT_CACHE_CAPACITY, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "experimental_cache")] | ||
| #[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)] | ||
| #[serde(deny_unknown_fields)] | ||
| /// Redis cache configuration | ||
| pub(crate) struct RedisCache { | ||
| /// List of URLs to the Redis cluster | ||
| pub(crate) urls: Vec<String>, | ||
| } | ||
|
|
||
| /// Configuration options pertaining to the sandbox page. | ||
| #[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)] | ||
| #[serde(deny_unknown_fields)] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be one line change if we stabilize it